January 2019
Beginner to intermediate
776 pages
19h 58m
English
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 # Python Network Programming Cookbook, Second Edition -- Chapter - 6 # This program is optimized for Python 2.7.12 and Python 3.5.2. # It may run on any other version with/without modifications. from getpass import getpass from fabric.api import local, run, env, get, put, prompt, open_shell def remote_server(): env.hosts = ['127.0.0.1'] env.password = getpass('Enter your system password: ') env.home_folder = '/tmp' def login(): open_shell(command="cd %s" %env.home_folder) ...Read now
Unlock full access