software you can take with you

Peter Foot

Microsoft Windows Phone Development MVP

How To: Use the FtpWebRequest

Networking In The Hand includes a full desktop-compatible implementation of the FtpWebRequest class. This plugs into the WebRequest class so that calling WebRequest.Create() with an FTP Uri will create an object of type FtpWebRequest. Because FTP support isn't built into the Compact Framework you have to register the class with this prefix using the the following code (only required once in your code):-

InTheHand.Net.FtpWebRequest.RegisterPrefix();

We have already looked at performing simple operations with the WebClient class. for more complex FTP operations you can use the FtpWebRequest directly. For example retrieving the modification date of a specific file:-

FtpWebRequest requestDate = (FtpWebRequest)FtpWebRequest.Create(requestUri);
requestDate.Method = WebRequestMethods.Ftp.GetDateTimestamp;
if (wc.Credentials != null)
{
   requestDate.Credentials = wc.Credentials;
}
FtpWebResponse responseDate = null;

responseDate = (FtpWebResponse)requestDate.GetResponse();

if (responseDate != null)
{
   MessageBox.Show(responseDate.LastModified.ToString());
   responseDate.Close();
}

Read the complete post at http://peterfoot.net/HowToUseTheFtpWebRequest.aspx

Published Oct 04 2007, 11:00 AM by Peter Foot
Filed under:
Copyright © 2001-2013 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy. OrcsWeb's Windows Cloud Server Hosting