Python 实现文件 FTP 上传下载
import paramiko
def sftp_upload_file(host,user,password,server_path, local_path):
try:
t = paramiko.Transport((host, 22))
t.connect(username=user, password=password)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.put(local_path, server_path)
print "upload success!"
t.close()
except Exception, e:
print e
def sftp_down_file(host,user,password,server_path, local_path):
try:
t = paramiko.Transport((host, 22))
t.connect(username=user, password=password)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.get(server_path, local_path)
print "download seccess!"
t.close()
except Exception, e:
print e
if __name__ == '__main__':
host = '10.120.228.254'
user = 'besread'
password = 'huaweif2'
local_path = 'F:/temp/tomcatKeyStore'
server_path ='/home/uwm/opt/container/conf/tomcatKeyStore'
sftp_down_file(host,user,password,server_path, local_path)
#sftp_upload_file(host,user,password,server_path, local_path)
pass
