tags:

views:

84

answers:

3

I am using ASP.NET 2.0 and I am trying, for the firs ttime, to ftp a file through the app. There are serveral examples on the net. This one made the most sense to me. Being unsure of the actual local it will be going, right now, I decidied to FTP it right back to my local host, figuring I have the credential so it would be a goo dtest. However, it is failing with the following error: "Unable to connect to the remote server".

public void FTPFile()
        {
            string CompleteFTPPath = "ftp://localhost//WebSite1/test.txt";
            string CompleteLocalPath = "C:\\test_file.txt";

        //Create a FTP Request Object and Specfiy a Complete Path 
        FtpWebRequest reqObj = (FtpWebRequest)WebRequest.Create(CompleteFTPPath);

        reqObj.Method = WebRequestMethods.Ftp.UploadFile;

        reqObj.Credentials = new NetworkCredential("<my user name>", "<my pw>");

        FileStream streamObj = File.OpenRead(CompleteLocalPath);

        byte[] buffer = new byte[streamObj.Length];

        streamObj.Read(buffer, 0, buffer.Length);

        streamObj.Close();
        streamObj = null;

        reqObj.GetRequestStream().Write(buffer, 0, buffer.Length);

        reqObj = null;
    }
+1  A: 

Make sure the ftp server is listening on the localhost (127.0.0.1) and not just on it's network ip address.

John Boker
A: 

Lets start with the basics.
Have you started a FTP server on your localhost?
Can you use a standard FTP client (either ftp in commandline or a downloaded ftp client like filezilla).

David Waters
A: 

unable to connect to remote server typically means exactly that; no server responded or you couldn't reach the server.

Do you have a local ftp server running? What happens when you point your web browser to ftp://localhost/" ?

To answer your question: No, probably not. :-)

Anders Lindahl