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

后端 未结 4 1180
刺人心
刺人心 2020-11-29 18:31

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

4条回答
  •  没有蜡笔的小新
    2020-11-29 19:08

    For those using Fabric 2, put can no longer upload directories, only files. Also, rsync_project is no longer part of the main Fabric package. The contrib package has been removed, as explained here. Now, rsync_project has been renamed to rsync, and you need to install another package in order to be able to use it:

    pip install patchwork

    Now, assuming you already have created a connection to your server:

    cxn = fabric.Connection('username@server:22')
    

    You can use rsync as below:

    import patchwork.transfers
    patchwork.transfers.rsync(cxn, '/my/local/dir', target, exclude='.git')
    

    Please refer to the fabric-patchwork documentation for more information.

提交回复
热议问题