gpt4 book ai didi

.net - 如何判断文件传输何时完成(服务器到客户端)

转载 作者:行者123 更新时间:2023-12-05 01:28:10 25 4
gpt4 key购买 nike

我正在从 ftp 服务器中提取文件,但我对验证传输是否成功完成的方法感到不满意。

感觉必须有更具体的方法来检测成功的转移。有任何想法吗?

我的代码:

            var request = (FtpWebRequest)FtpWebRequest.Create(ftpFilePath);

request.KeepAlive = false;
request.UseBinary = true;
request.UsePassive = false;
request.Credentials = new NetworkCredential("Username", "Password");
request.Method = WebRequestMethods.Ftp.DownloadFile;

FtpWebResponse response = (FtpWebResponse)request.GetResponse();

using (var stream = response.GetResponseStream())
{
using (var reader = new StreamReader(stream))
{
contents = reader.ReadToEnd();
}
}

//Check to see if transfer was successful
if (response.StatusDescription.StartsWith("2"))
transferSuccessful = true;

最佳答案

检查 FtpWebResponse.StatusCode为了成功。例如FtpStatusCode.ClosingData

关于.net - 如何判断文件传输何时完成(服务器到客户端),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10653573/

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