- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我刚开始使用 Python 的 pysftp,我对如何调用它的 walktree
函数感到困惑。
我找到了一些代码(位于 http://pydoc.net/Python/pysftp/0.2.8/pysftp/ )帮助我更好地理解我的参数应该采用什么形式
def walktree(self, remotepath, fcallback, dcallback, ucallback, recurse=True):
'''recursively descend, depth first, the directory tree rooted at
remotepath, calling discreet callback functions for each regular file,
directory and unknown file type.
:param str remotepath:
root of remote directory to descend, use '.' to start at
:attr:`.pwd`
:param callable fcallback:
callback function to invoke for a regular file.
(form: ``func(str)``)
:param callable dcallback:
callback function to invoke for a directory. (form: ``func(str)``)
:param callable ucallback:
callback function to invoke for an unknown file type.
(form: ``func(str)``)
:param bool recurse: *Default: True* - should it recurse
:returns: None
但我仍然对“为常规文件、目录和未知文件类型调用的回调函数”的确切含义感到困惑。
我也看了官方文档:https://media.readthedocs.org/pdf/pysftp/latest/pysftp.pdf
但它告诉我关于 walktree()
函数的所有信息是:
Is a powerful method that can recursively (default) walk a remote directory structure and calls a user-supplied callback functions for each file, directory or unknown entity it encounters. It is used in the
get_x
methods of pysftp and can be used with great effect to do your own bidding. Each callback is supplied the pathname of the entity. (form:func(str)
)
我觉得这并没有给我太多关于如何正确调用它的信息。
如果有人可以提供正确调用此函数的示例并解释为什么要传递所选参数,我们将不胜感激!
最佳答案
这是您正在寻找的示例代码。
import pysftp
file_names = []
dir_names = []
un_name = []
def store_files_name(fname):
file_names.append(fname)
def store_dir_name(dirname):
dir_names.append(dirname)
def store_other_file_types(name):
un_name.append(name)
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
sftp = pysftp.Connection(host="Your_ftp_server_name", username="ftp_username", private_key="location_of_privatekey", cnopts=cnopts)
sftp.walktree("/location_name/",store_files_name,store_dir_name,store_other_file_types,recurse=True)
print file_names,dir_names,un_name
文件名、目录名和未知文件类型分别存储在列表file_names
、dir_names
和un_name
中。
关于python - pysftp.Connection.walktree() 参数说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26600648/
我使用 pysftp(它是 paramiko 的包装器)。 import pysftp cnopts = pysftp.CnOpts() cnopts.hostkeys = None sftp=pys
我正在尝试使用 pysftp 连接到服务器传输文件。 每当我运行 con = pysftp.Connection('ftp.abc.com', username='user', password='m
我正在使用 Pysftp 来 sftp 放置大量文件,并且希望在它运行时获得一些进度输出,以便我知道它是如何做的。我可以使用详细选项(或等效选项)来获取该输出吗? 谢谢。 最佳答案 我可能在这里错误地
我尝试了以下三种更改目录的方法,但它永远不会改变。还有其他人遇到过这个问题吗? import pysftp cnopts = pysftp.CnOpts() cnopts.hostkeys = Non
我正在尝试使用以下脚本连接到服务器: import pysftp cnopts = pysftp.CnOpts() cnopts.hostkeys = None srv = pysftp.Connec
我在使用 pysftp 复制文件时遇到问题。这最初是一个有效的 WinSCP 脚本。我可以使用winscp.com 和filezilla 中下面的脚本中提供的凭据手动复制该文件。我已验证凭据是否正确并
我正在尝试编写一个脚本,以便在修改日期小于 24 小时的情况下从 SFTP 服务器检索文件。这是我迄今为止的尝试: cnopts = sftp.CnOpts() cnopts.hostkeys = N
我的代码: import pysftp s = pysftp.Connection(host='test.rebex.net', username='demo', password='password
使用 pysftp,我看到了如何在您已经连接后为任何命令设置超时,但我没有看到如何为连接本身设置超时。我觉得我在某处丢失了一些东西。只是为了尝试一下,我尝试添加 timeout=3到 Connecti
我想将我的实际私钥值作为参数传递,而不是提供文件路径。 到目前为止,我已经使用了以下代码: def upload_file_to_remote(hostname, port, username, pa
当我尝试连接时,我收到以下消息,需要一些帮助。我正在执行的脚本如下。关于如何解决此问题的任何建议? 此外,一旦我解决了这个问题,我就希望向此脚本添加监听功能,直到结果文件可用并从不同的远程目录下载它。
我正在尝试从远程服务器下载文件。为此,我需要定义“charset=ASCII”(我在 FileZilla 客户端中尝试过)。然后只有连接成功,我才能查看文件。否则我会从客户端收到“身份验证错误”(使用
我正在尝试建立到 sftp 服务器的测试连接。 (如 Python Pysftp Error 中所示)。我通过终端建立与服务器的第一个连接,从服务器获取了 key 。那工作完美无缺。但是,如果我运行
I am creating a backup script using pysftp module. I am able to upload and download files. When i am
我试图捕获 paramiko异常(exception),但它们仍被写入标准错误。 有没有办法停止在那里写? 编辑:它甚至发生在 paramiko 参与之前: import pysftp try:
我有一个用 Python 3 编写的小型服务,它使用 pysftp: with pysftp.Connection( host=host, username=connection_da
我正在使用 pysftp 库的 get_r 函数 ( https://pysftp.readthedocs.io/en/release_0.2.9/pysftp.html#pysftp.Connect
我是 Python 新手,正在编写一个使用 pysftp 模块的脚本。 pysftp 模块中有一个函数我遇到了问题——它是重命名函数。 这是电话 srv = pysftp.Connection(hos
我正在使用 python 3.3.2 和 pysftp 制作一个备份实用程序,该实用程序将文件副本存储在我网络上的另一台计算机上。 我已经知道如何使用 pysftp 来传输这些文件,但是我希望看到传输
我需要从服务器获取文件,然后将它们写入数据库。我使用: with pysftp.Connection(host, username=username, password=password, cnopt
我是一名优秀的程序员,十分优秀!