1. 程式人生 > >使用Python 實現文件的上傳與下載

使用Python 實現文件的上傳與下載

sport .get close OS imp down tran oca word

1,使用到Python的paramiko模塊

2,下面直接上代碼

import paramiko

localpath =r‘/tmp/a.txt‘
remotepath = r‘/mnt/b.txt‘

t = paramiko.Transport((ip,ssh_port))
t.connect(username="your login username",password="you password")
sftp =paramiko.SFTPClient.from_transport(t)

#download file
sft.get(remotepath,localpath)

#upload file
sft.put(localpath,remotepath)

sft.close()

使用Python 實現文件的上傳與下載