我想使用的FtpWebRequest在C#我的代码
// 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没有登陆,如果我尝试去一个浏览器页面,并在我写的网址ftp://192.168.20.10/眉毛页面问我要名和密码,我把相同的名称和密码,我看到FTP文件夹中的所有文件和文件夹。
Answer 1:
应该不是线路:
request.Credentials = new NetworkCredential("dev\ftp", "devftp");
是:
request.Credentials = new NetworkCredential("dev\\ftp", "devftp");
要么:
request.Credentials = new NetworkCredential(@"dev\ftp", "devftp");
我不得不相信,这可能会导致您的问题,因为\ f是换页符。
Answer 2:
面对同样的问题,这是我的解决方案:
request.Credentials = new NetworkCredential(
usernameVariable.Normalize(),passwordVariable.Normalize(),domainVariable.Normalize());
详细信息可以发现这里
希望能帮助到你。
Answer 3:
我发现通过.NET / C#连接到FTP服务器时,一些字符不是“有效”。 设置登录凭据只有数字和字母后[A-Z0-9]它的工作进行登录。
Answer 4:
只是删除从用户名或密码的双引号,因为在用户名有时$签名或密码导致的问题。 它很好用单引号每次。
文章来源: using ftpWebRequest with an error: the remote server returned error 530 not logged in