【发布时间】:2023-03-24 08:15:01
【问题描述】:
如何检查文件是否存在于我的 FTP 服务器中?我收到一个捕获异常,因为有时该文件不存在。
DateTime now = DateTime.Now;
string repotroday = "report_" + now.Year.ToString() + "_" + now.Month.ToString() + "_" + now.Day.ToString() + ".csv";
WebClient client = new WebClient();
string url = "ftp://vps.myserver.com/" + repotroday;
client.Credentials = new NetworkCredential("SURE", "iRent@123");
string contents = client.DownloadString(url);
但是,当我在 FTP 中没有报告时,它会返回:The remote server returned an error: (550) File unavailable (e.g., file not found, no access)
有没有办法在尝试下载之前检查文件是否存在?
谢谢
【问题讨论】:
-
虽然你真的需要检查吗?只需尝试下载文件并查看。