# create SSHClient instance
ssh = paramiko.SSHClient()
list = []
# AutoAddPolicy automatically adding the hostname and new host key
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.load_system_host_keys()
ssh.connect(hostname, port, username, password)
stdin, stdout, stderr = ssh.exec_command("cd *path*; ls")
for i in stdout:
list.append(i)
sftp = ssh.open_sftp()
for i in list:
tempremote = ("*path*" + i).replace('\n', '')
templocal = ("*path*" + i).replace('\n', '')
try:
#Get the file from the remote server to local directory
sftp.get(tempremote, templocal)
except Exception as e:
print(e)
远程服务器文件修改日期状态:2018年6月10日10:00:17
本地文件修改日期状态:当前日期时间
但是我发现在复制文件后,修改日期被改变了。
有没有办法同时将远程文件的状态和内容一起复制到本地文件中呢?
ls
命令来检索文件列表?使用 SFTP:SFTPClient.listdir
。 - Martin Prikryl