我正在尝试在 c# 中使用 ftpWebRequest 我的代码是
// 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 not logged in 如果我尝试进入浏览器页面并且在 url 我写ftp://192.168.20.10/浏览页面 要求我输入名称和密码,我输入相同的名称和密码,我可以看到 ftp 文件夹中的所有文件和文件夹。