是否可以通过 SSH 使用 os.walk? [英] Is it possible to use os.walk over SSH?
问题描述
我是 Python 新手,所以如果这是基本的,请原谅我,我已经搜索过但找不到答案.我正在尝试将 Perl 脚本转换为 Python (3.x),它连接到远程服务器并将给定目录中的文件复制到本地机器.传输的完整性至关重要,并且有几个内置步骤可确保传输的完整和准确.
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.
第一步是获取要传递给 rsync 的文件的完整列表.Perl 脚本具有以下几行来完成此操作:
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 {} \\;'`;
然后将两个列表join
以创建 $full_list.
The two lists are then join
ed to create $full_list.
我不想打开两个单独的 ssh
实例,而是打开一个并使用 os.walk
获取信息,使用:
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.
推荐答案
不,os.walk 不能这样使用.
No, os.walk can't be used in this way.
这篇关于是否可以通过 SSH 使用 os.walk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!