您当前的位置:首页 > 计算机 > 编程开发 > Python

Python 实现文件 FTP 上传下载

时间:12-14来源:作者:点击数:

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
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门
本栏推荐