Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to download files from FTP by windows service in c#.
Posted

ymmv, but there's some code here that shows how to use FTpWebRequest

Simple C# FTP Class[^]

MSDN Link : http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx[^]
 
Share this answer
 
Comments
rose lindo 16-Jul-13 6:50am    
Thanks
Hi Rose,

Here's a sample for downloading an FTP file from a remote server:
C#
public static void DownloadFtpFileSample()
{
    FtpWebRequest req = (FtpWebRequest)WebRequest.Create("ftp://MyFTPServer.com");
    request.Method = WebRequestMethods.Ftp.DownloadFile;

    // anonymous logon.
    req.Credentials = new NetworkCredential ("anonymous","theUser");

    FtpWebResponse response = (FtpWebResponse)req.GetResponse();

    StreamReader reader = new StreamReader(response.GetResponseStream());
    Console.WriteLine(reader.ReadToEnd());

    // That's it, you've downloaded your FTP file :)

    reader.Close();
    response.Close();
}
Cheers,
Edo
 
Share this answer
 
Comments
rose lindo 16-Jul-13 6:50am    
Thanks
rose lindo 16-Jul-13 6:51am    
My problem in reader.ReadLine()
Joezer BH 17-Jul-13 1:26am    
What problem are you getting?
rose lindo 17-Jul-13 1:57am    
Error is



-Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'
Joezer BH 17-Jul-13 2:20am    
Perhaps you're not checking the StatusCode and/or StatusDescription of the returned FtpWebResponse. If your code is assuming the connection and FTP request just works. It's probably returning an error of some kind, hence the stream your code is expecting isn't valid.


See:
http://stackoverflow.com/questions/1906858/how-to-check-ftpwebrequest-for-errors

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900