Event / On file transfer starts

19 views
Skip to first unread message

Ronan D

unread,
Dec 22, 2011, 10:35:51 AM12/22/11
to Python FTP server library - Discussion group
Hi,
First, thanks for your great work, pyftpdlib is an awesome piece of
code.
Question, how can I monitor current transfers being done?
I would like to monitor the transfers that are happenning, so indeed,
I would like to store the state of a transfer in a DB. I am able to do
it when a transfer finishes by overriding the
on_[incomplete_]file_received/sent methods, but how can I know when a
transfer starts?
Thanks again for your answers.
R.

PS : I'm using 0.6 version and using serve_forever(...) method to
launch the server

Giampaolo Rodolà

unread,
Dec 22, 2011, 11:00:25 AM12/22/11
to pyft...@googlegroups.com
> Hi,
> First, thanks for your great work, pyftpdlib is an awesome piece of
> code.

Thanks. =)

> Question, how can I monitor current transfers being done?
> I would like to monitor the transfers that are happenning, so indeed,
> I would like to store the state of a transfer in a DB. I am able to do
> it when a transfer finishes by overriding the
> on_[incomplete_]file_received/sent methods, but how can I know when a
> transfer starts?
> Thanks again for your answers.

As of right now there are no such callback but it might be a good idea
to have them.
Right now you can do this in the AbstractedFS, by overriding open method:


class CustomFS(ftpserver.AbstractedFS):

def open(self, filename, mode):
fileobj = CustomFS.open(self, filename, mode)
if 'r' in mode:
# sending (server -> client)
send_callback(filename)
else:
# receiving (client -> server)
recv_callback(filename)
return fileobj

> --
> You received this message because you are subscribed to the "Python FTP server library" project group:
> http://code.google.com/p/pyftpdlib/
> To post to this group, send email to pyft...@googlegroups.com
> To unsubscribe from this group, send email to pyftpdlib-...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/pyftpdlib

Ronan D

unread,
Jan 3, 2012, 6:50:11 AM1/3/12
to Python FTP server library - Discussion group
Thanks a lot for the information.
I will try that asap and will come back to you.
Cheers,
Ronan

Ronan D

unread,
Jan 16, 2012, 11:40:10 AM1/16/12
to Python FTP server library - Discussion group
Hi,
Your solution worked, thanks, I can now create a custom callback when
upload/download starts.
I come back to you with another related question:
Would you think it is possible to know what completion percentage the
current upload/download is? I guess not because of the way FTP
protocol works but I just wanted to know if you had a solution for
that...
thanks in advance,
Ronan

Giampaolo Rodolà

unread,
Jan 24, 2012, 2:33:44 PM1/24/12
to pyft...@googlegroups.com
Il 16 gennaio 2012 17:40, Ronan D <ronan.d...@gmail.com> ha scritto:
> Hi,
> Your solution worked, thanks, I can now create a custom callback when
> upload/download starts.
> I come back to you with another related question:
> Would you think it is possible to know what completion percentage the
> current upload/download is? I guess not because of the way FTP
> protocol works but I just wanted to know if you had a solution for
> that...
> thanks in advance,
> Ronan

You mean from the client perspective?
In that case the client can issue "STAT" command while the transfer is
in progress. The response will include the number of bytes
sent/received that far.
If you want to do this on the server side... well, DTPHandler class
stores that information into self.tot_bytes_sent and
self.tot_bytes_received attributes.
Those are updated in send() and handle_read() methods, every time a
chunk of data is sent/received.

Reply all
Reply to author
Forward
0 new messages