我不太明白这个问题,所以我试着猜一猜。
您应该能够查看远程服务器路径中的内容,而无需在本地下载文件。
^如果不想下载,{a1}不是正确的方法,因为根据文档:get(remotepath, localpath, callback=None) Copy a remote file
(remotepath) from the SFTP server to the local host as localpath. Any
exception raised by operations will be passed through. This method is
primarily provided as a convenience.
Parameters: remotepath (str) – the remote file to copylocalpath
(str) – the destination path on the local host callback (callable) –
optional callback function (form: func(int, int)) that accepts the
bytes transferred so far and the total bytes to be transferred
还有其他方法可以在远程目录中获取文件名和那些不需要下载的属性。
例如,listdir,listdir_attr和{a4}。在
例如,listdir_attr将Return a list containing SFTPAttributes objects corresponding to files
in the given path. The list is in arbitrary order. It does not include
the special entries '.' and '..' even if they are present in the
folder.
The returned SFTPAttributes objects will each have an additional
field: longname, which may contain a formatted string of the file’s
attributes, in unix format. The content of this string will probably
depend on the SFTP server implementation.
Parameters: path (str) – path to list (defaults to '.')
Returns: list
of SFTPAttributes objects
你可以从以下几点着手:list_png_files = []
for file_attributes in sftp.listdir_attr("remote_path"):
if file_attributes.filename.endswith('.png'):
list_png_files.append(file_attributes.filename)
当然,检查一下它是否会给出相对路径或绝对路径。
类似的,您可以尝试使用listdir,等等