python sftp code example
Example 1: python sftp put file
import pysftp
srv = pysftp.Connection(host="www.destination.com", username="root",
password="password",log="./temp/pysftp.log")
with srv.cd('public'):
srv.put('C:\Users\XXX\Dropbox\test.txt')
srv.close()
Example 2: python connect sftp
import pysftp
import sys
path = './THETARGETDIRECTORY/' + sys.argv[1]
localpath = sys.argv[1]
host = "THEHOST.com"
password = "THEPASSWORD"
username = "THEUSERNAME"
with pysftp.Connection(host, username=username, password=password) as sftp:
sftp.put(localpath, path)
print 'Upload done.'