Python + Paramiko implements sftp file upload and download
Recently, in the test server, I looked at the Paramiko module. I have always used the FileZilla tool. After thinking about it, continuous integration and updating the code can be done with Parmmiko, which is still good.
Paramiko is a module written in python language, which can connect to Linux server remotely, view the log status above, configure remote server in batches, upload files, download files, etc.
Initialize some parameters:
Paramiko executes linux commands remotely:
Paramiko upload file:
Paramiko download file:
Python also has a default ftplib module that defines the FTP class, which has limited functions and can be used to implement a simple ftp client for uploading or downloading files.
FTP related command operations:
Some small examples:
Parmmiko completes the sftp file transfer operation very well, and can be used for continuous integration development or testing in SVN management code projects
Original link: http://blog.csdn.net/Temanm/article/details/50607741
There is also a more detailed article here, which is shared here to help deepen understanding.
The paramiko module provides the functions of ssh and sft to remotely log in to the server to execute commands and upload and download files. This is a third-party software package that needs to be installed before use.
1 sshclient login based on username and password
2 The transport method login
method based on user name and password 1 is a traditional operation of connecting to the server, executing commands, and closing. Sometimes it is necessary to log in to the server to perform multiple operations, such as executing commands and uploading/downloading files. Method 1 cannot be implemented , which can be operated as follows
3 SSHClient login based on public key
4 Login via key-based Transport
##### File transfer SFTP ###########
5 Realize the function of returning the result immediately after entering the command The
above operations are all basic connections. If we want to implement a function similar to the xshell tool, after logging in, we can enter the command and press Enter to return the result:
6 Support tab auto-completionOriginal link: http://www.ifindbug.com/doc/id-44934/name-paramiko of python module.html
In fact, watching these Chinese version of the tutorial, if you can solve your problem, it is indeed more convenient and fast. However, once you encounter a problem and various abnormalities occur, you will not know how to solve it after reading these Chinese tutorials, so you still need to develop a search for the Internet at the beginning to see what methods are available (which modules of python, Which methods) can solve similar problems, and then consult the specific official API, so that the specific methods, parameters, and usage methods are clear at a glance, and the memory will be more profound, and there will be more sense of accomplishment after solving the problem. Therefore, it is more advisable to go to the official API to check the specific usage. When the problem cannot be solved, don’t go back and look at the official API again. I believe that the clues of the problem will be found here, so as to solve the problem. of.