Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy a directory to a remote machine using Fabric?

Tags:

python

fabric

I have a directory on my local machine that I would like to copy to a remote machine (and rename it) using Fabric. I know I can copy file using put(), but what about a directory. I know it's easy enough using scp, but I would prefer to do it from within my fabfile.py if possible.

like image 505
gaviscon_man Avatar asked Mar 15 '11 16:03

gaviscon_man


1 Answers

You can use put for that as well (at least in 1.0.0):

local_path may be a relative or absolute local file or directory path, and may contain shell-style wildcards, as understood by the Python glob module. Tilde expansion (as implemented by os.path.expanduser) is also performed.

See: http://docs.fabfile.org/en/1.0.0/api/core/operations.html#fabric.operations.put


Update: This example works fine (for me) on 1.0.0.:

from fabric.api import env from fabric.operations import run, put  env.hosts = ['[email protected]']  def copy():     # make sure the directory is there!     run('mkdir -p /home/frodo/tmp')      # our local 'testdirectory' - it may contain files or subdirectories ...     put('testdirectory', '/home/frodo/tmp')  # [[email protected]] Executing task 'copy' # [[email protected]] run: mkdir -p /home/frodo/tmp # [[email protected]] put: testdirectory/HELLO -> \ #     /home/frodo/tmp/testdirectory/HELLO # [[email protected]] put: testdirectory/WORLD -> \ #     /home/frodo/tmp/testdirectory/WORLD # ... 
like image 200
miku Avatar answered Oct 13 '22 04:10

miku