C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
help with downloading files Posted by quinny019 on 21 Jan 2009 at 1:42 PM
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....

WebClient request = new WebClient();
Uri newuri=new Uri("ftp://ftp.fedex.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);

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
Report
Re: help with downloading files Posted by itdelphia on 22 Jan 2009 at 9:32 PM
you can try to manually connect to server as anonymous
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","janeDoe@contoso.com");
    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;
}


Report
Re: help with downloading files Posted by quinny019 on 22 Jan 2009 at 11:05 PM
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
Report
Re: help with downloading files Posted by itdelphia on 24 Jan 2009 at 10:56 PM
well, in this case, you can check the Code Access Security for .net or firewall setting in you computer.
Report
Re: help with downloading files Posted by quinny019 on 27 Jan 2009 at 9:04 AM
how might I do that?
Report
Re: help with downloading files Posted by itdelphia on 27 Jan 2009 at 8:52 PM
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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.