开发者

Is my ftp issue a coding error or credentials error?

I am using ASP.NET 2.0 and I am trying, for the first time, to ftp a file t开发者_StackOverflow中文版hrough the app. There are several 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 decided to FTP it right back to my local host, figuring I have the credential so it would be a good test. 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;
    }


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


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).


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. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜