gpt4 book ai didi

C# FTP ListDirectoryDe​​tails问题

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

我尝试从包含 1000 多个文件的目录中的 FTP 读取文件列表。

我是这样做的:

    public static FtpWebRequest GetRequest(string uri)
{
FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
req.Credentials = new NetworkCredential("login", "password");
req.KeepAlive = false;
req.UseBinary = false;
req.UsePassive = true;
return req;
}

public static bool CheckConnection()
{
FtpWebResponse respSize = null;
try
{
FtpWebRequest reqFTP = GetRequest(@"ftp://myftp.com");
reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
respSize = (FtpWebResponse)reqFTP.GetResponse();
respSize.Close();
respSize = null;
reqFTP.GetResponse().Close();

return true;
}
catch (Exception ex)
{

//...
}
finally
{
if (respSize != null)
respSize.Close();
}
return false;
}

我得到一个错误:

The remote server returned an error:

(451) Local error in processing.

atSystem.Net.FtpWebRequest.SyncRequestCallback(Objectobj)

atSystem.Net.FtpWebRequest.RequestCallback(Objectobj)

atSystem.Net.CommandStream.Dispose(Booleandisposing)

at System.IO.Stream.Close()

at System.IO.Stream.Dispose()

atSystem.Net.ConnectionPool.Destroy(PooledStreampooledStream)

atSystem.Net.ConnectionPool.PutConnection(PooledStreampooledStream, Object owningObject,Int32 creationTimeout, BooleancanReuse)

atSystem.Net.FtpWebRequest.FinishRequestStage(RequestStagestage)

atSystem.Net.FtpWebRequest.SyncRequestCallback(Objectobj)

atSystem.Net.FtpWebRequest.RequestCallback(Objectobj)

atSystem.Net.CommandStream.Abort(Exceptione)

atSystem.Net.CommandStream.CheckContinuePipeline()

atSystem.Net.FtpWebRequest.DataStreamClosed(CloseExStatecloseState)

atSystem.Net.FtpDataStream.System.Net.ICloseEx.CloseEx(CloseExStatecloseState)

atSystem.Net.FtpDataStream.Dispose(Booleandisposing)

at System.IO.Stream.Close()

atSystem.Net.FtpWebResponse.Close()

at CheckConnection()

有人知道这是怎么回事吗?

问候马尔辛

最佳答案

来自 RhinoSoft(FTP 软件 Serv-U 的制造商):

"A 451 reply code may be sent in response to any command initiating a file transfer. It is a transient negative response, which means the error condition is a temporary one. It is usually sent in response to the server encountering an unexpected local error when processing data it is transferring or receiving. In this case, the client is encouraged to restart the FTP transaction and try again." [1]

因此,这可能是您的软件与 FTP 服务器之间的通信问题,不一定是您的软件本身的问题。

增加 FtpWebRequestTimeout 属性的长度不会有什么坏处,但根据我的研究,这不太可能是原因。

关于C# FTP ListDirectoryDe​​tails问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6254126/

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