My wife is out of town for a while and I got stuck handling some manual FTP downloads for her. NASA has a program where they process remote satellite imagery into HDF (Hierarchical Data Format) files for scientific analysis -- in case you weren't aware, my wife is a marine scientist doing a lot of remote sensing work right now. She told me NASA would email her every once in a while when an HDF file was ready to be downloaded; they have an automated system that processes the images and then notifies any scientists that have registered to get the images. The catch is that the images are only available to download for 3 days since they consume a lot of FTP server space. Since my wife is in the field for the next several weeks (months, actually...) I told her I would handle the downloading of her images. NASA changed her email address to mine and we were all set.
Until this weekend.
I checked my email Saturday and found 80 messages from the NASA automated processing system. Mercy! This morning (Sunday) there were another 50 messages from NASA! I don't think my wife expected this sort of volume (and if she did we'll have to have a little chat when she returns . . .), but I know I better get those files before the 3 days expires or else . . . so this is why I wrote a little application to handle it.
Using this FTP library by Jaimon Mathew made my Sunday mission a piece of cake. I've worked with it before and never had any problems; this time was no exception. I wrote a quick interface to capture the ip address of the server, the directory, and the file to download via FTP; I store this data in a DataTable and when I press the magic “Download” button I iterate through the rows performing the FTP download like this:
public static void getFile( string strIP, string strFolder, string strFile, string strNewFolder )
{
FTPFactory ff = new FTPFactory();
ff.setDebug(true);
ff.setRemoteHost( strIP );
ff.login(); //I'm omitting the authentication portion
if( strFolder.Length > 0 )
{
ff.chdir( strFolder );
}
else
{
return; //no folder means there's nothing to download
}
try
{
ff.download( strFile, strNewFolder + "/" + strFile );
}
catch( Exception ex )
{
System.Diagnostics.Trace.Fail( ex.ToString() );
}
ff.close();
}
Mission accomplished, thanks to the easy to use FTP Library referenced above. Note that the FTPFactory class supports authentication against the server too, but I omitted that to keep the NASA security folks happy (not that anyone from NASA is reading this, but you never know . . . ). If I keep getting 50+ FTP notifications a day, I might add multi-threading to it or some level of asynchronous behaviour -- perhaps even hooking it into exchange directly or use an Outlook Macro -- but since this is just a convenience thing for me, I'm opting to keep it very simple right now. Not bad for work done before Sunday breakfast!
Happy .Netting!