Directory transfers with Paramiko

前端 未结 10 898
刺人心
刺人心 2020-11-30 07:25

How do you use Paramiko to transfer complete directories? I\'m trying to use:

sftp.put(\"/Folder1\",\"/Folder2\")

which is giving me this e

10条回答
  •  心在旅途
    2020-11-30 08:20

    As far as I know, Paramiko does not support recursive file upload. However, I have found a solution for recursive upload using Paramiko here. Follows an excerpt of their recursive upload function:

       def _send_recursive(self, files):
            for base in files:
                lastdir = base
                for root, dirs, fls in os.walk(base):
                    # pop back out to the next dir in the walk
                    while lastdir != os.path.commonprefix([lastdir, root]):
                        self._send_popd()
                        lastdir = os.path.split(lastdir)[0]
                    self._send_pushd(root)
                    lastdir = root
                    self._send_files([os.path.join(root, f) for f in fls])
    

    You may try to either use their function SCPClient.put invoking the above function for recursive upload or implement it on your own.

提交回复
热议问题