pyftpdlib callback on sending file

852 Views Asked by At

I'm currently developing an ftp server using pyftpdlib by giampaolo. I've been struggling since I need to process stuff when the server receive the RETR commnand before sending a given file.

My question is, is there any form of implementing a callback or tweaking the source so I can do such validation over a file before it is sent, and if so how would I implement it?

1

There are 1 best solutions below

0
Giampaolo Rodolà On

You can simply override ftp_RETR method:

from pyftpdlib.handlers import FTPHandler

class Handler(FTPHandler):

    def ftp_RETR(self, file):
        if not condition:
            self.respond("500 sorry!")
        else:
            super(Handler, self).ftp_RETR(file)