Re: How to access files and folders inside a ftp site? Hi..
Here I have given the sample code for FTP file download. It will help you to implement the FTP file functionality in your C#. // Set up the request FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(downloadUri);
// use the provided credentials
if (this._isAnonymousUser == false)
{ftpRequest.Credentials = new NetworkCredential(this._userName, this._password); } // Download a file. Look at the other methods to see all of the potential FTP features ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile; // get the response object
FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
Stream stream = null;
StreamReader reader = null;
StreamWriter writer = null; // get the file as a stream from the response object and write it as
// a file stream to the local PC try
{stream = ftpResponse.GetResponseStream();
reader = new StreamReader(stream, Encoding.UTF8);
writer = new StreamWriter(destinationFile, false);
writer.Write(reader.ReadToEnd());
return ftpResponse.StatusCode; }
finally
{// Allways close all streams stream.Close();
reader.Close();
writer.Close(); }
Hope it will help you to manage the FTP file. If anything else let me know
thanks 
__________________ Karpagarajan. R Necessity is the mother of invention
Last edited by Karpagarajan : 03-23-2007 at 03:43 AM.
|