Python – Connect SFTP and Upload files

We have recently been involved in one of the automations where we must upload the csv file automatically daily to vendor Secure FTP.

This time we have utilized Python instead of PowerShell because of project requirements.

I am sharing the code samples here to achieve it.

Module required:

Download the code samples from git hub

https://github.com/VikasSukhija/Python

First Sample à fetchhostkeyssftp

This script sample will assist you in fetching the host keys from spftp and save it in designated folder.

This is required many a times by secureftp to avoid man in the middle attacks.


Another code sample is Upload2Sftp:

This script will upload the csv file from local path to remote path.


As in the above screenshot you can see local path is D:\temp\vendor.csv and it will upload to root/import/vendor.csv on sftp server.

Note: These are code samples only and not the whole script.

 

 

Thanks for reading ….

Tech Wizard

 

https://techwizard.cloud

https://syscloudpro.com/

PowerShell Fast Track

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s