Finding a fully working, lightweight FTP client, that had no GUI, was free, and came with source code, was difficult. This API is based on a work, Jaimon Mathew had done, and I have added some methods, cleaned up the code, debugged it and added some error handling, logging, debugging etc.
It is easy to use. Here is a code example:
FtpClient ftp = new FtpClient(FtpServer,FtpUserName,FtpPassword);
Not so difficult now, is it? I am using it in my WebCamService list on this site, so if you want to see it in action, go here.
I started out wrapping fully the
WinInet API, but it was such a labourous task that it made sense just to do the FTP. Since Microsoft has great support for HTTP, I could skip that, and later work on SMTP.
- Recursive upload
- Create directory
- Asynchronous operation
- Not fully tested
- No real error handling
- No download recourse yet
- Rename will overwrite, if the target already exists
A little more advanced, the asynchronous operation is used when you need the job, to fork while your code continues over the method. All asynchronous methods start with
Using it is simple. You need a couple of things, an
AsyncCallback object and a method which it handles.
private FtpClient ftp = null;
private void UploadPicture(string imagePath)
string FtpServer = ConfigurationSettings.AppSettings["FtpServer"];
string FtpUserName = ConfigurationSettings.AppSettings["FtpUserName"];
string FtpPassword = ConfigurationSettings.AppSettings["FtpPassword"];
AsyncCallback callback = new AsyncCallback(CloseConnection);
ftp = new FtpClient(FtpServer,FtpUserName,FtpPassword);
private void CloseConnection(IAsyncResult result)
if ( ftp != null ) ftp.Close();
ftp = null;
When the upload finishes or throws an exception, the
CloseConnection method will be called.