I'm new to Python so forgive me if this is basic, I've searched but can't find an answer. I'm trying to conve开发者_高级运维rt a Perl script into Python (3.x) which connects to a remote server and copies the files in a given directory to the local machine. Integrity of the transfer is paramount and there are several steps built-in to ensure a complete and accurate transfer.
The first step is to get a complete listing of the files to be passed to rsync. The Perl script has the following lines to accomplish this:
@dir_list = `ssh user@host 'find $remote_dir -type f -exec /bin/dirname {} \\;'`;
@file_list = `ssh user@host 'find $remote_dir -type f -exec /bin/basename {} \\;'`;
The two lists are then join
ed to create $full_list.
Rather than open two separate ssh
instances I'd like to open one and use os.walk
to get the information using:
for remdirname, remdirnames, remfilesnames in os.walk(remotedir):
for remfilename in remfilesnames:
remfulllist.append(os.path.join(remdirname, remfilename))
Thank you for any help you can provide.
No, os.walk can't be used in this way.
This looks like a usable walk-function. Currently not tested by me. https://pysftp.readthedocs.org/en/release_0.2.8/pysftp.html#pysftp.Connection.walktree
精彩评论