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

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

PowerShell Fast Track


Leave a Reply

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

You are commenting using your 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