Solved

Design of Server with FTP server interaction

Posted on 2003-11-10
9
202 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
  • 5
  • 2
9 Comments
 
LVL 11

Accepted Solution

by:
KurtVon earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 11

Expert Comment

by:KurtVon
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:KurtVon
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now