Search code examples
cftpftp-serverpureftpd

Where does pure-ftpd call its uploadscript?


I've been looking through pure-ftpd-1.0.42 source code:

https://github.com/jedisct1/pure-ftpd

Trying to find when it triggers:

https://github.com/jedisct1/pure-ftpd/blob/master/src/pure-uploadscript.c

i.e. when does it run the uploadscript after a file has been uploaded.

If you look in src/ftp_parser.c the dostor method is how a file starts the upload journey. Then it goes to ul_send then ul_handle_data but I get lost at this point. I never see when it says, okay, this file is now uploaded, time to call uploadscript. Can someone show me the line?


Solution

  • In the pureftpd_start() function in src/ftpd.c, pure-ftpd starts up and parses all of its command-line options. It also opens a pipe to the pure-uploadscript, if configured; here. Rather than invoking the upload script on each upload (and incurring the fork() and exec() overhead per-upload), pure-ftpd keeps the upload script process running separately, and sends it the uploaded file path via the pipe.

    Knowing this, then, we look for where that pipe is written to, using the upload_pipe_push() function. Interestingly, that function is called here, by the displayrate() function, which is called by both dostor() and doretr() in the src/ftpd.c file.

    Hope this helps!