help with downloading files - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help with downloading files

quinny019quinny019 Posts: 5Member
So I there wasnt a visual J# forum on this site, so I figured that C# was the closest to it, so I posted in here thinking that some1 might somewhat familiar with J#. I am trying to download a file off of an ftp server using WebClient.Here is my code....

[code]
WebClient request = new WebClient();
Uri newuri=new Uri("ftp://ftp.fedex[size=1][/size].com/pub/us/rates/downloads/documents2/Ground.txt");
String pathname="C:\Documents and Settings\2346298\My
Documents\Visual Studio 2005\Projects\ShippCalculator\ShippCalculator\Ground.txt";

request.DownloadFile(newuri,pathname);
[/code]
When I compile and run I get an exception saying...
"System.Net.WebException: The underlying connection was closed: An unexpcted error occured on a recieve."

I am not sure how to fix this... I hope someone can help me out here

Comments

  • itdelphiaitdelphia Posts: 28Member
    you can try to manually connect to server as anonymous
    [code]
    public static bool DisplayFileFromServer(Uri serverUri)
    {
    // The serverUri parameter should start with the ftp:// scheme.
    if (serverUri.Scheme != Uri.UriSchemeFtp)
    {
    return false;
    }
    // Get the object used to communicate with the server.
    WebClient request = new WebClient();

    // This example assumes the FTP site uses anonymous logon.
    request.Credentials = new NetworkCredential ("anonymous","[email protected]");
    try
    {
    byte [] newFileData = request.DownloadData (serverUri.ToString());


    System.IO.File.WriteAllBytes(pathname, newFileData); // write data to file
    }
    catch (WebException e)
    {
    Console.WriteLine(e.ToString());
    }
    return true;
    }

    [/code]
  • quinny019quinny019 Posts: 5Member
    ive seen that code before... the problem is when i type "request.Credentials" i get an error that says that it doesnt recognize the field "Credentials".... the thing is this ftp server address is totally public... you could go into internet explorer or any browser for that matter and type the the address I am looking to download from. My colleague is writing a similar program to mine in C#, and the exact code i posted above works perfectly..... and when she tries the WebClient code on her computer in her own J# project it works... i dont know what to do.. because I think it might be just my computer
  • itdelphiaitdelphia Posts: 28Member
    well, in this case, you can check the Code Access Security for .net or firewall setting in you computer.
  • quinny019quinny019 Posts: 5Member
    how might I do that?
  • itdelphiaitdelphia Posts: 28Member
    you can use .Net Framework x.x configuration tool, can be found in control panel -> admin tools.

    Or you can use command promt with Caspol.exe to grant your assembly security policy.

    If you r not family with these tools, you can try some research in MSDN fo find out. ( help command can also ... help. )

    - maybe your ftp port connection is accidently disabled. Check your firewall config to find out.
Sign In or Register to comment.