How to get size of remote file?

隐身守侯 提交于 2020-01-03 15:57:46

问题


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( cs.host, username = 'test', password = 'test', timeout=10)
sftp = ssh.open_sftp()
res = sftp.put(filepath, destination )

?


回答1:


Use the .stat() method:

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

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

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




回答2:


You can use this method:

lstat(self, path)

See paramiko docs



来源:https://stackoverflow.com/questions/14834442/how-to-get-size-of-remote-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!