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 underlying objects by calling the close() method separately on each object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.152.159