def sftp_upload(host,port,username,password,local,remote):
sf = paramiko.Transport((host,port))
sf.connect(username = username,password = password)
sftp = paramiko.SFTPClient.from_transport(sf)
try:
if os.path.isdir(local):#?????????????
for f in os.listdir(local):#??????
sftp.put(os.path.join(local+f),os.path.join(remote+f))#????????
else:
sftp.put(local,remote)#????
except Exception,e:
print('upload exception:',e)
sf.close()
#if __name__ == '__main__':
# host = '121.69.75.194'#??
# port = 22 #??
# username = 'wac' #???
# password = '8112whz' #??
# local = '/Users/ngxin/Documents/xin/face_recognition/my_faces/'
# remote = '/home/wac/ngxin/ftp_upload/'
# local = 'F:\\sftptest\\'#?????????????????windows?????window???????????
# remote = '/opt/tianpy5/python/test/'#?????????????????linux????
#sftp_upload(host,port,username,password,local,remote)#??
#sftp_download(host,port,username,password,local,remote)#??
评论列表
文章目录