gpt4 book ai didi

c# - FtpWeb 请求 : The remote server returned an error: (530) Not logged in

转载 作者:太空宇宙 更新时间:2023-11-03 13:23:21 24 4
gpt4 key购买 nike

我一直收到错误消息“远程服务器返回错误:(530) 未登录。”当调用 FtpWebRequest.GetResponse() 时。我怀疑这是因为我错误地配置了用于基本身份验证的 FTP 站点,但我不确定。我读过其他帖子,但解决方案似乎围绕着 NetworkCredential 对象中指定的不正确凭据。我希望能够通过 SSL 将凭据传递到 ftp 站点。我已将问题隔离到一个测试项目中。在这里,主要是从 msdn https://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.enablessl(v=vs.110).aspx 复制的:

public static void Main(string[] args)
{
// Only use this to get around issues with self-signed certificates...
ServicePointManager.ServerCertificateValidationCallback =
delegate (object s, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors) { return true; };

ListFilesOnServerSsl(new Uri("ftp://127.0.0.1:21"));

Console.WriteLine("Press any key...");
Console.ReadKey();
}

public static bool ListFilesOnServerSsl(Uri serverUri)
{
// The serverUri should start with the ftp:// scheme.
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return false;
}
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.UseBinary = false;
request.EnableSsl = true;

// Need to use credentials to log in...
request.Credentials = new NetworkCredential("TestFtpUser", "IDontKnow");

// Get the ServicePoint object used for this request, and limit it to one connection.
// In a real-world application you might use the default number of connections (2),
// or select a value that works best for your application.

ServicePoint sp = request.ServicePoint;
Console.WriteLine("ServicePoint connections = {0}.", sp.ConnectionLimit);
sp.ConnectionLimit = 1;

FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("The content length is {0}", response.ContentLength);
// The following streams are used to read the data returned from the server.
Stream responseStream = null;
StreamReader readStream = null;
try
{
responseStream = response.GetResponseStream();
readStream = new StreamReader(responseStream, System.Text.Encoding.UTF8);

if (readStream != null)
{
// Display the data received from the server.
Console.WriteLine(readStream.ReadToEnd());
}
Console.WriteLine("List status: {0}", response.StatusDescription);
}
finally
{
if (readStream != null)
{
readStream.Close();
}
if (response != null)
{
response.Close();
}
}


Console.WriteLine("Banner message: {0}",
response.BannerMessage);

Console.WriteLine("Welcome message: {0}",
response.WelcomeMessage);

Console.WriteLine("Exit message: {0}",
response.ExitMessage);
return true;
}

以下是在 IIS 中的本地主机上创建 ftp 站点的屏幕截图:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

我注意到在设置基本身份验证时 IIS 没有要求我输入密码。我不知道这是为什么。我不应该对 FTP 站点使用基本身份验证吗?

非常感谢!

最佳答案

原来是我在IIS中配置ftp站点时,没有在机器上配置本地用户帐号来匹配“指定用户”。转到“控制面板”=>“用户帐户”=>“用户帐户”=>“管理用户帐户”=>“管理用户帐户”=>添加并将用户添加到我的本地计算机后,消息“( 530) 未登录”已经消失。

关于c# - FtpWeb 请求 : The remote server returned an error: (530) Not logged in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41895741/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com