服务器上复制不了文件路径,如何从服务器获取文件位置路径而不复制它?

我不太明白这个问题,所以我试着猜一猜。

您应该能够查看远程服务器路径中的内容,而无需在本地下载文件。

^如果不想下载,{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,等等

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值