Geeks With Blogs
Fórmulas e Cenas Object Reference Not Set to an Instance of an Object

FileStream outputStream = new FileStream("c:\myfilefolder\file.txt");
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://myFTPSite/file.txt"));

reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential("myUser","MyPassword","FTPDomain");

FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();

int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];

readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
    outputStream.Write(buffer, 0, readCount);
    readCount = ftpStream.Read(buffer, 0, bufferSize);
}

ftpStream.Close();
outputStream.Close();
response.Close();

 

Enjoy :)

Posted on Thursday, October 7, 2010 11:24 AM Geral , C# | Back to top


Comments on this post: How to: Download a file using FTP

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Sglima | Powered by: GeeksWithBlogs.net