使用带有错误的ftpWebRequest:远程服务器返回未登录错误530 [英] using ftpWebRequest with an error: the remote server returned error 530 not logged in

查看:134
本文介绍了使用带有错误的ftpWebRequest:远程服务器返回未登录错误530的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在c#中使用ftpWebRequest我的代码是

I am trying to use the ftpWebRequest in c# my code is

// Get the object used to communicate with the server.
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://192.168.20.10/file.txt");
            request.Method = WebRequestMethods.Ftp.UploadFile;

            // This example assumes the FTP site uses anonymous logon.
            request.Credentials = new NetworkCredential("dev\ftp", "devftp");

            // Copy the contents of the file to the request stream.
            StreamReader sourceStream = new StreamReader(@"\file.txt");
            byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
            sourceStream.Close();
            request.ContentLength = fileContents.Length;
            request.UsePassive = true;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(fileContents, 0, fileContents.Length);
            requestStream.Close();

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

            response.Close();

,我在request.GetRequestStream()中得到一个错误.错误是:远程服务器返回未登录错误530如果我尝试进入浏览器页面并在URL中输入 ftp://192.168.20.10/浏览页面要求我输入名称和密码,我输入相同的名称和密码,然后在ftp文件夹中看到所有文件和文件夹.

and I get an Error in request.GetRequestStream(); the error is: the remote server returned error 530 not logged in if I try to go in to a browser page and in the url I write ftp://192.168.20.10/ the brows page is asking me for a name and password, I put the same name and password and I see all the files and folders in the ftp folder.

推荐答案

不应该这样:

request.Credentials = new NetworkCredential("dev\ftp", "devftp");

是:

request.Credentials = new NetworkCredential("dev\\ftp", "devftp");

或:

request.Credentials = new NetworkCredential(@"dev\ftp", "devftp");

我必须相信,这可能是导致您出现问题的原因,因为\ f是换页符.

I have to believe this may be causing your issues because the \f is a form feed character.

这篇关于使用带有错误的ftpWebRequest:远程服务器返回未登录错误530的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆