Can I use os.walk through SSH?

I am new to Python, so forgive me if this is basic, I searched but cannot find the answer. I am trying to convert a Perl script to Python (3.x), which connects to a remote server and copies the files in the given directory to the local computer. Transmission integrity is of utmost importance and several steps are built in to ensure complete and accurate transmission.

The first step is to get a complete list of files that rsync will transfer. To execute this, the Perl script has the following lines:

@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 {} \\;'`; 

Two lists then join ed to create $ full_list.

Instead of opening two separate ssh instances that I would like to open, 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)) 

Thanks for any help you can provide.

+4
source share
2 answers

No, os.walk cannot be used this way.

+3
source

This seems like a useful walking feature. Currently I have not tested. https://pysftp.readthedocs.org/en/release_0.2.8/pysftp.html#pysftp.Connection.walktree

0
source

Source: https://habr.com/ru/post/1335286/


All Articles