我有窗口服务,可以从ftp服务器下载文件,下面是下载文件的代码。但是它会下载4-5个文件,然后在此行停止-'sftp.DownloadFile(remoteDirectory + remoteFileName,file1)'。我正在使用Renci.SshNet ddl。如果停止,如何恢复下载?如果您能帮助我,那就太好了!
if (sftp.Exists(remoteDirectory))
{
var files = sftp.ListDirectory(remoteDirectory);
var filterfiles = (from a in files
where (a.Name.StartsWith(FileInitial))
select a).ToList();
foreach (var file in filterfiles)
{
string remoteFileName = file.Name;
if ((!file.Name.StartsWith(".")))
{
string[] arr1 = remoteFileName.Split('_');
if (arr1.Length > 2)
{
using (Stream file1 = File.OpenWrite(localDirectory + remoteFileName))
{
try
{
sftp.DownloadFile(remoteDirectory + remoteFileName, file1);
}
catch(Exception Ex)
{
}
}
}
}
}
}