Ftp!

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
Okay,

I've read a few things in different places on how to set up the basic functionality of FTP communication using Windows Sockets, (System.Net.Sockets Namespace, Socket Class) at it seems pretty straight forward. You send a command to the FTP and then read the responses and parse the response CODES (like 200, 220, 150, 226, 331, etc) and voila you can send a command and get a response from the FTP. However, how do program in the downloading of a file? The Socket class has a SendFile() method but no RecieveFile() method, so I were to send the command to the FTP:
GET thisfile.txt
or
RETR myfile.txt

How would I receive it on my end?
One of the tutorials I read had a constant named SENDING_DATA_ON_PORT_20, which equated to the 150 FTP response code, which happens when sending ASCII on /bin/ls (or dir for a directory listing) as well as when invoking a GET/RETR command. With applications like WS_FTP and hell, even the CMD shell FTP program, they seem to be able to do this, but I have found nothing out there that says: Here is how you retrieve an ASCII file mode transfer from an FTP server, and here is how you retrieve a BINARY file mode transfer form an FTP server.

Could anyone point me in the right direction to learn how to do this? As well as gain file information specifics from the FTP server instead of parsing the DIR or (LS -l) response text.

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
 
You have the WebClient class, it works for both Http and Ftp. There is also a FtpWebRequest class, that has more functionality. Finally if you want/need to go deep you can continue with TcpClient class (which is Socket+NetworkStream), it would then be required for you to know RCF959 for starters, this is sufficient for passive transfer - for active you also need a TcpListener to receive the data you have requested on the command channel.

There is no way to get "specific" information except parsing the listing as far as I know.
edit: there is, but it's tedious unless you only want size or date of one file. For FtpWebRequest you can set Method to one of the WebRequestMethods.Ftp values GetDateTimestamp (MDTM) or GetFileSize (SIZE).
 
Back
Top