使用的FtpWebRequest一个错误:远程服务器返回错误530不loged [英] using ftpWebRequest with an error: the remote server returned error 530 not loged in
问题描述
我试图使用的FtpWebRequest在c#
我的代码是
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
不loged如果我尝试去一个浏览器页面,并在网址我写的 ftp://192.168.20.10/
眉毛页面问我名和密码,我把相同的名称和密码,我看到所有的文件和文件夹在FTP文件夹中。 ?
任何一个可以帮我解决这个问题。
and I get an Error in request.GetRequestStream(); the error is: the remote server returned error 530 not loged 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. can any one help me with this problem?
推荐答案
应该不是行:
request.Credentials = new NetworkCredential("dev\ftp", "devftp");
是:
be:
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不loged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!