Simple file download via FTP 
Author Message
 Simple file download via FTP

Hi,

I am trying to create a web service in C# that connects to an FTP server and
downloads a text file to my web server.  I have found numerous examples of
complicated FTP classes on the web but I cannot seem to get these to work,
the one which looked most promising is located at
http://www.*-*-*.com/

The code I am using to use this class is as follows, it's basically a copy
and paste from the examples webpage:

[WebMethod]
public void FTPTest()
{
    try
    {
        FTPFactory ff = new FTPFactory();
        ff.setDebug(true);

ff.setRemoteHost(ftp://tgftp.nws.noaa.gov/data/observations/metar/decoded/);
        ff.setRemoteUser("anonymous");
        ff.setRemotePass("anonymous");
        ff.login();
        string[] fileNames = ff.getFileList("*.*");
        ff.download("EGAC.TXT", false);
        ff.close();
    }

    catch(Exception e)
    {
        Console.WriteLine("Caught Error :"+e.Message);
    }

Quote:
}

but it returns the following error when I do this:

System.Net.Sockets.SocketException: The requested name is valid and was
found in the database, but it does not have the correct associated data
being resolved for at System.Net.Dns.GetHostByName(String hostName) at
System.Net.Dns.Resolve(String hostName) at FtpLib.FTPFactory.login() at
XMLWeatherGenerator.Service1.myTest() in
e:\website\inetpub\wwwroot\xmlweathergenerator\service1.asmx.cs:line 63

I have no idea what this means, could anybody shed any light on the subject
or suggest an easier way of downloading the files from the server, I will
always know the names of the files on the server so I don't need to do
anything fancy,

Thanks in Advance,

Dave King.



Sat, 17 Apr 2004 08:07:43 GMT  
 Simple file download via FTP
Dave,

Quote:
> I am trying to create a web service in C# that connects to an FTP server
and
> downloads a text file to my web server.  I have found numerous examples of
> complicated FTP classes on the web but I cannot seem to get these to work,
> the one which looked most promising is located at
> http://www.csharphelp.com/archives/archive9.html

Hmm, I'd think twice about using that code.  There are no timeouts, and it
appears that the following code will hang forever if the server returns
exactly 512 bytes in reply to some command:

 private string readLine() {

    while(true) {
        bytes = clientSocket.Receive(buffer, buffer.Length, 0);
        mes += ASCII.GetString(buffer, 0, bytes);
       if(bytes < buffer.Length) {
                                                   break;
                                      }
                           }

FTP components are complicated for a reason. :-)

--
Zane Thomas
www.mabry.com/dotnet



Sat, 17 Apr 2004 08:34:43 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. how to download a file from http or ftp

2. Downloading file from FTP to PPC2002

3. FTP file download through proxy fails

4. How download file from FTP

5. Download file via WebClient

6. downloading a file via http

7. getting files via ftp

8. Upload a file via ftp?

9. Upload a file via ftp?

10. FTP/NET Beta 1 Download Now Available

11. FTP download resuming

12. C and/or C++ FTP site downloads.

 

 
Powered by phpBB® Forum Software