SCP vs SFTP
Through Paramiko can also transfer files, how to transfer files between computers through Paramiko, by reading official documents, found in the following two ways:
Sftp=Paramiko.Sftpclient.From_transport(Ssh.get_transport ()) Span class= "PLN" style= "padding:0px; margin:0px; Outline:medium none; Color: #000000; " >sftp = Ssh.open_sftp ()
That is, create a new Sftpclient object that will reuse the previous SSH connection, so when we use SFTP to transfer files, we do not need to authenticate the user again.
File Upload
Inch [59]:Sftp.Put(' memory.py ', ' memory.py ') Out[59]: <Sftpattributes: [Size=288Uid=1000Gid=1000Mode=0100644 Atime=1435391914 mtime< Span class= "pun" style= "padding:0px; margin:0px; Outline:medium none; Color: #000000; " >=1435391914 ]>
File download
Inch [60]: Sftp. get ( ' memory.py ' , backup.py ")
Execute command
Paramiko does not provide a sub-module called SCP, if we want to transfer data between computers, can be through SFTP (SFTP implementation of all SCP functions, there is no need to implement an SCP) transfer files, you can also execute the command via SFTP, as follows:
Inch [44]:Sftp.Listdir() Out[44]: ['. Viminfo ', '. Bash_logout ', '. Bash_history ', ' Agentbackkup_2015-06-10 ', ' Agentbackup ', ' Rdsagent '] Inch [45]:Sftp.Rename(' Agentbackkup_2015-06-10 ', ' Agentbackkup_2015-06-11 ') Inch [46]:Sftp.Listdir() Out[46]: [' Agentbackkup_2015-06-11 ', '. Viminfo ', '. Bash_logout ', '. Bash_history ' ,< Span class= "PLN" style= "padding:0px; margin:0px; Outline:medium none; Color: #000000; " > , ' rdsagent ' "
SFTP offers a number of commands, which can be found in the official documentation.
Python transfer files between different computers to achieve similar SCP function does not lose password