Solved

Design of Server with FTP server interaction

Posted on 2003-11-10
9
216 Views
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 thereafter...so 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 http://www.ftpserverapi.com 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.

0
Comment
Question by:sandeep_th
[X]
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
9 Comments
 
LVL 11

Accepted Solution

by:
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 (http://packages.qa.debian.org/b/bsd-ftpd.html) 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.
0
 
LVL 11

Expert Comment

by:KurtVon
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.

http://www.wu-ftpd.org/man/ftpaccess.html - see the mailserver and incmail settings (there are probably equivalent for other ftp daemons if you have the manual)

0
 
LVL 17

Assisted Solution

by:rstaveley
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.
0
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

by:KurtVon
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.
0
 
LVL 11

Expert Comment

by:KurtVon
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);
        else
            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.
0
 
LVL 17

Expert Comment

by:rstaveley
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 (http://www.wu-ftpd.org/wu-ftpd-faq.html#QA71), 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.
0
 
LVL 11

Expert Comment

by:KurtVon
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.
0
 
LVL 9

Expert Comment

by:tinchos
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.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

740 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