Design of Server with FTP server interaction

Posted on 2003-11-10
Last Modified: 2010-04-02
Hi All,
We are in the process of designing a server to be written in C++ on Linux. Actually calling it a server might be a misnomer because there's no  interaction with the client other than receiving files from it and then going on to process the files. The client is practically left out of the loop it is basically a pure ftp client.

One way we thought this might work is that this "server" might work in conjunction with an FTP server(say vsftp) in such a way that the ftp server notifies our "server" each time a file transfer is effected and completed. Then our "server" reads this file and starts processing it.

We certainly don't want to write a ftp server of our own.

Now the question is....does any FTP server on Linuxoffer some kind of an API or something which allows us to conceive any such thing at all? Something like that is there for windows for example.

 All our "server" needs is that it should be notified that a particular file transfer is complete...and the file is available in the ftp home directory.

If this is not possible, could anyone suggest any alternative way to do this...without having to write an ftp server of our own.

Question by:sandeep_th
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
LVL 11

Accepted Solution

KurtVon earned 200 total points
ID: 9715464
I worked in a shop a year or so ago with similar requirements.  Documents would arrive at an ftp location and the be filed off depending on the type of document it was.  This was on IIS, so we may have a different problem than under linux -- remember the source for several ftpd daemons are available ( so you could just roll your own fairly easily.

Unfortunately, we were not given that luxury and, with a ridiculous amount of research, we finally just wrote a windows service (linux daemon) that checked the directory every minute to see if anything new had arrived.  It isn't that hard.

Hope this helps.
LVL 11

Expert Comment

ID: 9718457
Ah, here's a possibility.  Apparently, it is possible to send an email when the ftp daemon recieves a file.  Not particularly useful, but you could set up the machine as a mailserver, and have it mail itself.  the mail could then trigger a script to process the notification.  I know procmail is capable of this.

Rather circuitous, but possible. - see the mailserver and incmail settings (there are probably equivalent for other ftp daemons if you have the manual)

LVL 17

Assisted Solution

rstaveley earned 200 total points
ID: 9719938
wu-ftpd and others have implemented the site exec command, which you can use to execute non-standard commands on the server from the client. I believe you just put the relevant executable into the ~ftp/bin, but I confess I've always used crontab for this kind of thing.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 11

Expert Comment

ID: 9722354
Site exec?  Isn't that Latin for "remote root-kit"?  :-)

I think sandeep_th is looking for something to run automatically when a file is uploaded.  Isn't site-exec for programs explicitly activated by the person doing the uploading?  Because of all the vulnerabilities discovered in it, and even if the command itself is made safe the programs it calls can wreak havoc if not perfectly secured, I haven't even given it more than a cursory look, so I suppose it might work if it can be invoked automatically.
LVL 11

Expert Comment

ID: 9722465
Oh, and if you do decide to go with the modified ftp daemon, the BSD ftp I linked to above can be modified without violating any copyrights (it's even BSD, so you can sell the modified version without distributing the source).

This is just based on a quick overview of the source (remarkably clean I might add) but it looks like the point you want to hook into is the end of the function "store".  The place in the code is:

    if (receive_data(din, fout) == 0) {
        if (unique)
            reply(226, "Transfer complete (unique file name:%s).", name);
            reply(226, "Transfer complete.");

        // The following was added:
        // Set a flag here to detect a completion if you only want to
        // respond to completed files.
        // Don't forget this is a C program, not C++, so declare the
        // flag at the top of the function, not down here.
    (void) fclose(din);

    // The following was added:
    // Check the flag here if you only want to respond to completed files, but
    // either way, call the script/program/whatever at this point.  The name of
    // the file is in "name"

    data = -1;
    pdata = -1;

Hope this helps.
LVL 17

Expert Comment

ID: 9723097
It is certainly true to say that ftp-wu had a site exec buffer overflow vulnerability and I read that slackware had a sloppy set-up (, but that's no reason to throw the baby out with the bath water. If clients are using scripts to FTP files, site exec should be a good tool to trigger approved scripts on the server.
LVL 11

Expert Comment

ID: 9723198
Well, since the only ftp server I run allows wide-open anonymous FTP (sure it's behind a firewall, but so is our WAP) I'm not exactly the best guy to go to for extreme security :-)

I had forgotten that sandeep_th said they were writing the client too, so you are right, that is a reasonable option.  For some reason I had got it in my head that the client was just an ordinary ftp client.

Expert Comment

ID: 10248841
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: KurtVon {http:#9715464} & rstaveley {http:#9719938}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question