Introduction

For my first experience writing a C# component I decided to implement an FTP Component. This is the sample code to use the component. The component code is not really guaranteed to work fine in this state, but I thought that it might be of some interest and that feedback will help to improve or correct features.

Simply add the component to the ToolBox (Using customize Toolbox) and put it on your form. The code project contains a simple FTP Client. You may have to change FTPCom Reference in TestFTPCom project to test the sample. Remove the old reference and Add Reference to FtpCom.DLL

Getting a directory listing

The DirCompleted event is received when Dir command is completed FileCount contains the number of files, use IsFolder to find if File is a folder. GetFileName and GetFileSize return the name and the size of the files

Note : File Collection is not implemented in this version as it should be!

Close the connection

ftpc.Disconnect();
ServerView.Items.Clear();

Hope this help. Any comments are welcome.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

-- which is running on .NET Framework 1.1 or higher,
-- which can automatically put together splitted files on the server,
-- which allows to download only a part of a file on the server,
-- which allows to resume any broken download,
-- which automatically starts a separate thread,
-- which can be aborted any time from your main thread,
-- which supports UTF8 encoded filenames,
-- which has a built-in download scheduler,
-- which has a built-in bandwidth control,
-- which has a built-in preview function for the download of movies,
-- which automatically reconnects the server after an error has occurred,
-- which displays download progress in percent and in bytes and the remaining time,
-- which writes a detailed logging for all operations it does,
-- which is based on Wininet.dll and has one workaround for each of the 4 known Wininet.dll bugs,
-- which is very well tested and bug-free,
-- which is written by a very experienced programmer and has a very clean and well documented sourcecode,

The code works fine for me.But I encountered an interesting problem which I would like to share out here with those folks who are going to use this FTP Component.

After login and connecting to the remote FTP server, when it does a file listing, I was not able to get the full directory contents listed due a minor bug in DataAsyncSocket.cs in the function:

public void ReceiveCallback( IAsyncResult ar )

What was going on was that inside this function, there is a part which checks for the data received and would terminate if the data ended with a CRLF (\r\n) and while I was testing my application, I noticed that every line would come with a CRLF and I was very very lucky to have ended my string variable with the CRLF before the end of the dir listing.

In the end I modified the code to look like this: (LOOK OUT FOR MATHACHAN)

Hi, I'm Mario from Italy.
Can someone explain me how I can intercept an FTP Event ?
I try to explain.
I know that some IP address send me a file by FTP. I want to know by C# code when this happens.
Anyway I need a kind of listener which tells me who send the file and where it is headed.

edtFTPnet is open source and free, and will always remain so. It's released under LGPL. Here is a download link that includes both source and binaries.

You may have gotten edtFTPnet confused with one of the commercial versions (i.e. edtFTPnet/Express or edtFTPnet/PRO). These add some features to edtFTPnet that are useful for some commercial applications, but the free version is a full-featured FTP client library that is used (free of charge) by tens of thousands of developers.

I realize that simply flogging a commercial product in a forum such as this is unethical and I would not do this. However, edtFTPnet really is free and open source, so I believe that it is acceptable and (hopefully) useful for readers of the forum.

// Then it occurs error: The given path's format is not supported.
// But it works when using your test project, how can I do?
// In addition, if I want to upload file to one folder in the remote server,
// e.g. "lesson", how to change the current folder of the remote server,
// DirChange(...)?