Transferring files to a remote machine over SSH
While automating a remote system administration task using Fabric, if you want to transfer files between your local machine and the remote machine with SSH, you can use the Fabric's built-in get()
and put()
functions. This recipe shows you how we can create custom functions to transfer files smartly by checking the disk space before and after the transfer.
Getting ready
This recipe also needs Fabric to be installed first. You can install Fabric using Python packing tools, pip
or easy_install
, as shown in the following command:
$ pip install fabric
Here, we will connect the remote host using the SSH protocol. So, it's necessary to install and run the SSH server on the remote host.
How to do it...
Let us first set up the Fabric environment variables and then create two functions, one for downloading files and the other for uploading files.
Listing 6.6 gives the code for transferring files to a remote machine over SSH as follows:
#!/usr/bin/env python...