如何获取远程文件的大小? [英] How to get size of remote file?

查看:58
本文介绍了如何获取远程文件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 sftp paramiko 客户端在上传文件后获取远程文件的大小??

How to get size of remote file after upload file, using sftp paramiko client ? ?

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect( 'hostname', username = 'test', password = 'test', timeout=10)
sftp = ssh.open_sftp()
res = sftp.put(filepath, destination )

?

推荐答案

使用 .stat() 方法:

Use the .stat() method:

info = sftp.stat(destination)
print(info.st_size)

.stat() 方法遵循符号链接;如果这不理想,请使用 .lstat() 方法代替.

The .stat() method follows symlinks; if that is not desirable, use the .lstat() method instead.

请参阅SFTPAttributes 类信息 哪些属性可用..st_size 是字节大小.

See the SFTPAttributes class information for what attributes are available. .st_size is the size in bytes.

这篇关于如何获取远程文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆