how to copy file from local to sftp using python

Solutions on MaxInterview for how to copy file from local to sftp using python by the best coders in the world

showing results for - "how to copy file from local to sftp using python"
Jana
29 Oct 2016
1import paramiko
2import os
3
4paramiko.util.log_to_file('logfile.log')
5
6host = "101.102.103.104"
7port = 22
8transport = paramiko.Transport((host, port))
9password = "pass"
10username = "user"
11
12sftp = paramiko.SFTPClient.from_transport(transport)
13
14filepath = '~/remote/file'
15localpath = '~/local/file'
16sftp.get(filepath, localpath)
17
18sftp.close()
19transport.close()
20