SFTP: max bytes to be transferred

D

Dario Beraldi

Hello,

I'm using the module paramiko to transfer files via sftp (see code below).
I would like to specify the maximum amount of bytes to be transferred
(say 10MB, if the file is bigger just transfer up to these many bytes).

From the docs of paramiko
(http://www.lag.net/paramiko/docs/paramiko.SFTPClient-class.html#get)
I see that the method get() can take an optional callback parameter
which is a "function that accepts the bytes transferred so far and the
total bytes to be transferred". This seems to do what I need but I
don't know how to specify such callback function. Any idea?

This is my code:
------------[ Cut here ]-------------

import paramiko
host = "my.host"
port = 22
transport = paramiko.Transport((host, port))

password = "mypassword"
username = "myname"
transport.connect(username = username, password = password)

sftp = paramiko.SFTPClient.from_transport(transport)

filepath = 'file/to/myfile.txt'
localpath = 'D:/Tritume/myfile.txt'

sftp.get(filepath, localpath) ## <-- Calback function should go here

------------[ cut here]-----------

Many thanks
Dario



--

Dr. Dario Beraldi
Institute of Evolutionary Biology
University of Edinburgh
West Mains Road
Edinburgh EH9 3JT
Scotland, UK


--

Dr. Dario Beraldi
Institute of Evolutionary Biology
University of Edinburgh
West Mains Road
Edinburgh EH9 3JT
Scotland, UK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top