我们公司的网站托管在 ORCSWEB 中。 ORCS端已经制定了某种政策和规则。当人们尝试使用错误的凭据访问我们公司的 ftp 3 次并失败时,我们的 ftp 将被锁定。我们经常通过编程方式通过 ftp 上传文件,但有时会发现 ftp 锁定。所以我与 orcsweb 技术支持人员交谈:他们说我们正在尝试通过代码匿名访问我们的 ftp。所以我用来访问 ftp 的代码如下。因此,请检查我的代码并告诉我代码中存在什么问题导致匿名访问,因为我尝试使用正确的凭据进行访问。
public static string IsFtpAccessible(string FTPAddress)
{
string strError = "";
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(FTPAddress);
FtpWebResponse res;
StreamReader reader;
ftp.Credentials = new NetworkCredential("myuserid", "00000password");
ftp.KeepAlive = false;
ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
ftp.UsePassive = true;
ftp.UseBinary = true;
ftp.KeepAlive = false;
try
{
using (res = (FtpWebResponse)ftp.GetResponse())
{
reader = new StreamReader(res.GetResponseStream());
}
}
catch(Exception ex)
{
strError = "ERROR:" + ex.Message.ToString();
}
return strError;
}
所以告诉我我的代码中缺少什么导致匿名访问。
最佳答案
服务器上必须允许匿名访问,根据您的描述,我认为不允许匿名访问。通常,匿名访问凭据的提供方式如下:
request.Credentials = new NetworkCredential ("anonymous","<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="553f343b30113a3015363a3b213a263a7b363a38" rel="noreferrer noopener nofollow">[email protected]</a>");
要点是电子邮件地址就是密码。
如果您只是有时发现基于代码的 FTP 被锁定,那么这不是您的问题所在。
关于c# - 通过ftp C#匿名访问和文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13499967/