Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get size of remote file?

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 )

?

like image 890
Bdfy Avatar asked Feb 12 '13 14:02

Bdfy


2 Answers

Use the .stat() method:

info = 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.

like image 63
Martijn Pieters Avatar answered Nov 07 '22 09:11

Martijn Pieters


You can use this method:

lstat(self, path)

See paramiko docs

like image 35
thikonom Avatar answered Nov 07 '22 08:11

thikonom