# 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)
Remote Server File Date Modified Stat : 6/10/2018 10:00:17
Local File Date Modified Stat : Current datetime
But I found that the date modified changed after done copy the file.
Is there anyway to copy remote file along with the file stat to the local file too ?
ls
command to retrieve file a list? Use SFTP:SFTPClient.listdir
. – Chas