Skip to content

How do I use the FTP classes?

The FTP classes follow the FtpWebRequest in the full .NET framework. Add a reference to InTheHand.dll and InTheHand.Net.dll to your project and add the following to your code file:-

using InTheHand.Net;

using System.Net;

using InTheHand.IO;

On startup e.g. in your Form constructor add:-

FtpWebRequest.RegisterPrefix();

This allows you to create FtpWebRequests using WebRequestCreate for any url with the ftp:// schema

To download a file you can use code like this:-

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp://yourserver/path/filename.txt);

FtpWebResponse response = (FtpWebResponse)request.GetResponse();
System.IO.Stream stream = response.GetResponseStream();System.IO.FileStream fileStream = new System.IO.FileStream(“\\Local File Name.txt”, System.IO.FileMode.Create);
stream.CopyTo(fileStream);

fileStream.Close();

stream.Close();

The default Method for an FtpWebRequest is RETR (download). To upload a file you would set Method to “STOR” and write the file contents to the stream retrieved from GetRequestStream(). The full list of available methods can be found in InTheHand.Net.WebRequestMethods.Ftp.

Feedback and Knowledge Base