Is it possible to use os.walk over SSH?

Posted by LeoB on Stack Overflow See other posts from Stack Overflow or by LeoB
Published on 2011-01-12T18:21:04Z Indexed on 2011/01/12 18:53 UTC
Read the original article Hit count: 169

Filed under:
|

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 convert 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 joined 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.

© Stack Overflow or respective owner

Related posts about python

Related posts about python-3.x