Python transfer files between different computers to achieve similar SCP function does not lose password

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.