import paramiko
hostname = ‘’
username = ‘’
password = ‘’
ssh = paramiko.SSHClient() #创建一个SSH客户端client对象
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname,username=username,password=password) #创建SSH连接
tran = ssh.get_transport()
sftp = paramiko.SFTPClient.from_transport(tran)
remote_path = “/roy_file/my_file”
local_path = r"D:\yitu"
sftp.get(remote_path,local_path)
ssh.close()
错误:
remote_path = “/roy_file/my_file”
local_path = r"D:\yitu"
解决方法
local_path = r"D:\yitu\my_file"
注意:这里的remotepath和localpath为:“文件所在目录 + ‘/’ + 文件名” 完整的文件路径,不是只有文件的目录