Python Network Programming
by Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
How it works...
This recipe can take the various inputs for connecting to a remote machine and copying a file over SFTP.
This recipe passes the command-line input to the copy_file() function. It then creates an SSH client calling the SSHClient class of paramiko. The client needs to load the system host keys. It then connects to the remote system, thus creating an instance of the transport class. The actual SFTP connection object, sftp, is created by calling the SFTPClient.from_transport() function of paramiko. This takes the transport instance as an input.
After the SFTP connection is ready, the local file is copied over this connection to the remote host using the put() method.
Finally, it is a good idea to clean up the SFTP connection and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access