Finding a fully working, lightweight FTP client that had no GUI, was free, and came with source was difficult. This API is based on one Jaimon Mathew had done, and I have added some methods, cleaned up the code, debugged it, added some error handling, logging, debugging etc.
It is easy to use. Here is a code example:
FtpClient ftp = new FtpClient(FtpServer,FtpUserName,FtpPassword);
ftp://ftp.login/();
ftp.Upload(@"C:\image.jpg");
ftp://ftp.close/();
Not so difficult now is it? I started out wrapping fully the WinInet API, but it was sucha labourous task that it made sense to just to the FTP, sinse Microsoft has great support for HTTP, I could skip that, and later work on SMTP.
Asynchronous operation
A little more advanced, the asynchronous operation is for when you need the job to fork while your code continues over the method. All asynchronous method start with Begin.
Using it is simple. You need a couple of things, an AsyncCallback object and a method which it handles, like so:
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);
ftp://ftp.login/();
ftp://ftp.beginupload(imagepath/, callback);
ftp://ftp.close/();
}
private void CloseConnection(IAsyncResult result)
{
Debug.WriteLine(result.IsCompleted.ToString());
if ( ftp != null ) ftp://ftp.close/();
ftp = null;
}
When the upload finishes (or throws an exception), the CloseConnection method will be called.
Louis Sanz RodriguezPosted Jul 13, 2015, 6:58 PM
tanks
Sanford StaabPosted Dec 11, 2012, 3:33 PM
Recommend upload read the file with RO attributes to have minimal security impact. Also I need the async form to locate state from the callback - an example would be wonderful! Thanks for this very useful class!
Chuck WoodPosted Apr 19, 2012, 4:01 PM
This FTP library worked out very well for trying to FTP a lightweight Zebra printer FTP server with xml files.
MATHANPRABU GANESANPosted May 21, 2011, 3:54 PM
Is there any way to increase performance of upload file?
Kevin GerndtPosted Apr 13, 2011, 2:16 AM
Hey, i found a good working ftp class for c# at http://kevingerndt.blogspot.com/2011/04/ftp-klasse-fur-c.html.
jomo juthaPosted Apr 12, 2011, 12:06 PM
the uploading of a folder is VERY slow, i am wondering how to speed it up. what would be your suggestion ?
Muhammad ShakirPosted Apr 7, 2010, 9:53 AM
hi Is it workable for window mobile ce 5. I am looking ftp client class for mobile application in c#. regards, Ahsan shakir
kik kikPosted Jul 24, 2009, 7:04 AM
I'm a beginner and i was having some trouble with this. altough the class works fine when I use the upload() method it tries to find the file on the server computer (since asp.net works onthe server). I was wondering how to get the file from the users computer. i know this is kind of stupid but pls bear with me i'm only a beginner experimenting and learning
JamiePosted May 25, 2009, 6:05 AM
Is it possabe to get the output of this control e.g. wrong password, file uploaded, server does not exist etc Thanks
Nisarg ShahPosted Nov 6, 2008, 1:52 AM
can anybody tell me the solution??? I am using the master pages and in the content pages i am using the Update panel control of AJAX But when i run website sometimes i am not getting the contents which i have put in update panel and sometimes its is displayed... this problem occurs specifically in IE6 this works fine with IE7, means contents are getting displayed in IE7 but not in IE6... Please Help me...... Thanx in advance.........
dEEPESHPosted Sep 30, 2008, 10:46 AM
I am getting error when login The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for on this line of code addr = Dns.Resolve(this.server).AddressList[0]; pls help
abhi sinPosted Aug 27, 2008, 1:30 AM
good
liangPosted Dec 18, 2007, 11:00 PM
can i get all directories ?
liangPosted Dec 18, 2007, 10:47 PM
can i get all directories ?
Steve BerwickPosted Nov 13, 2007, 3:33 PM
thanks for the library, this is exactly what i was looking for!
Joe KunchandyPosted Oct 24, 2007, 2:57 PM
which namespace i have to use to get access to FtpClient class.