views:

60

answers:

6

What I want to do is run a process on my server that acts like an FTP server. So people can upload things through "FTP" but really it's a program I'm running that lets me put information about that file in a database and not really put the files where they say they're going.

E.g. Website Templates. A user of my service wants to put up the template they are working on for a client of theirs, but wants to upload it through the FTP in their text editor. But I want to store that templates data in a database, process it to find out things about it then store it where I want to but still display it as being where the person put it for them.

Probably going to be very difficult but does anyone know if it's possible?

+1  A: 

It's trivially possible.

The FTP protocol is relatively simple.

You're just creating a specialized FTP server (or "daemon").

Start with any open-source FTP server and begin to customize. Example: http://code.google.com/p/pyftpdlib/

S.Lott
This isn't what I would call "trivial."
tster
The question was "is it possible". The answer is trivially, "yes, it's possible". And, since there's complete source, it's trivial to make changes. I'm not sure where your threshold of "trivia" lies, but having written customized FTP clients, I can say that it's very, very simple. Given source, it's trivial.
S.Lott
A: 

I've not done this particular activity before, but I think this is a perfect candidate for implementing this with LUFS (linux userspace filesystem). Then you should be able to use a standard ftp-server which then writes to your userspace filesystem where you only have to provide the appropriate behaviour.

I know there are python bindings available, and probably others floating around...

ChristopheD
A: 

Its not so trivial as it looks.If the server you are running supports only HTTP then making an ftp connection to it won't be easy unless you hack the implementation to support ftp.

If you ftp to a url instead of using http then the server gets the request in ftp protocol and the port that receives the request must be able to handle the protocol in which the request comes.Most server implementation have support for FTP but that will ftp the files to some directory.After uploading the files to a directory, you can use a daemon to parse and put them in the database and later delete them.

Rajat
A: 

It might be better to install a existing ftp server and write a script or process that watches the filesystem for new and updated files. Once the watching process sees an update it handles it appropriately.

Plenty of ftp servers are feature rich and hardened against attacks which you would have to worry about if you wrote your own. vsftpd, proftpd are two OSS ftp servers worth mentioning.

Mark Carey
A: 

FTP only defines the specifics of the transfer operation. How the actual storage is handled is up to whoever's writing the server. This allows it to be filesystem-agnostic, so that the same protocol can be used against Unix, Windows, VMS, TRS-DOS, etc.

One option would be to find the source for an existing server that runs on your platform of choice and just "replace" the calls that deal with the file I/O.

dbfs.h:


#define open db_open
#define write db_write
#define close db_close

dbfs.c:


int open(...)
{
    /* create a memory buffer */
}

ssize_t write(...)
{
    /* write data to memory buffer */
}

int close(...)
{
    /* execute SQL insert statement to save memory buffer to db */
}

Existing server code:


#include <fcntl.h>
#include <unistd.h>
#include "dbfs.h" /* "replaces" system-defined file I/O routines */
Dewayne Christensen
Your was actually quite right, I hadn't read the RFC 959 yet and now that I have it explains the same thing in there. I've actually already started on making the server in Ruby and have gotten quite far with it. It works completely, but I've been working on it literally from about 10am till well... its now 12:38 and I'm adding some new features. But it works great and does all the usual stuff and is kinda stable, but still needs a fix on the timeouts. Check it out http://wiki.github.com/FluffyJack/Custom-FTP-Server
FluffyJack
A: 

Hey Thanks Everyone

I've actually already started after reading the RFC 959 document (yes, the WHOLE thing... took hours).

If you want, you can have a look at how I'm going here http://wiki.github.com/FluffyJack/Custom-FTP-Server

It would be great if you gave me some feedback on how I'm going.

Right now it does all the usual stuff, manages threaded connections, requires login, makes, stores, deletes, and retrieves, lists, files and directories, etc. Doesn't do PASV yet, still working on that, really tricky trying to workout what it's actually meant to do.

Working well though. Works fine locally for using FTP on all my folders on my computer, kinda funny using FTP to work on files locally :)

Anyway, thanks again everyone, especially Dewayne Christensen who actually came up with the best point, FTP is all about just creating a standard interface between two "Filesystems"

FluffyJack