更新 FtpHelper.cs
ow
This commit is contained in:
parent
296d989acd
commit
9001ae19d6
76
FtpHelper.cs
76
FtpHelper.cs
@ -519,12 +519,12 @@ namespace quarto.cbo.util
|
||||
return;
|
||||
}
|
||||
//下載整個目錄下的內容
|
||||
public void DownloadFiles(string remoteFolder, string localFolder)
|
||||
public int DownloadFiles(string remoteFolder, string localFolder)
|
||||
{
|
||||
DownloadFiles(remoteFolder, localFolder, null);
|
||||
return DownloadFiles(remoteFolder, localFolder, null);
|
||||
}
|
||||
//下載整個目錄下的內容
|
||||
public void DownloadFiles(string remoteFolder, string localFolder, string passFilePath)
|
||||
public int DownloadFiles(string remoteFolder, string localFolder, string passFilePath)
|
||||
{
|
||||
if (!Directory.Exists(localFolder))
|
||||
{
|
||||
@ -538,18 +538,23 @@ namespace quarto.cbo.util
|
||||
logManager.Log("----------------------------------Download Folder:" + remoteFolder, LogLevel.INFO, this);
|
||||
|
||||
List<FtpItem> fis = List();
|
||||
if (fis == null || fis.Count == 0) return;
|
||||
if (fis == null || fis.Count == 0) return 0;
|
||||
string tempCurrentDirectory = currentDirectory;
|
||||
|
||||
string[] passFilePaths = null;
|
||||
|
||||
if (!string.IsNullOrEmpty(passFilePath)) passFilePaths = passFilePath.Split(new char[] { ';', ',' });
|
||||
|
||||
if (passFilePaths != null && passFilePaths.Length > 0)
|
||||
passFilePaths = passFilePaths.Where(x => !string.IsNullOrEmpty(x)).ToArray();
|
||||
string tempRemoteFolder = null;
|
||||
|
||||
int totalFiles = 0; // 累计下载的文件总数
|
||||
|
||||
foreach (FtpItem fi in fis)
|
||||
{
|
||||
tempRemoteFolder = remoteFolder + "/" + fi.Name;
|
||||
if (passFilePaths != null && passFilePaths.Length > 0 && passFilePaths.Any(x => x.Trim().ToUpper() == tempRemoteFolder.Trim().ToUpper()))
|
||||
|
||||
if (passFilePaths != null && passFilePaths.Length > 0 && passFilePaths.Any(x => tempRemoteFolder.Trim().ToUpper().StartsWith(x.Trim().ToUpper() + "/")))
|
||||
{
|
||||
logManager.Log(">>>>>>>>>>>Pass Folder:" + tempRemoteFolder, LogLevel.INFO, this);
|
||||
continue;
|
||||
@ -560,15 +565,72 @@ namespace quarto.cbo.util
|
||||
if (fi.IsFolder)
|
||||
{
|
||||
logManager.Log("DownloadFolder:" + tempRemoteFolder, LogLevel.INFO, this);
|
||||
DownloadFiles(tempRemoteFolder, localFolder + "\\" + fi.Name);
|
||||
totalFiles += DownloadFiles(tempRemoteFolder, localFolder + "\\" + fi.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
logManager.Log("DownloadFiles:" + tempRemoteFolder, LogLevel.INFO, this);
|
||||
download(tempRemoteFolder, localFolder + "\\" + fi.Name);
|
||||
Files.Add(localFolder + "\\" + fi.Name);
|
||||
totalFiles++; // 每下载一个文件,计数加1
|
||||
}
|
||||
}
|
||||
|
||||
return totalFiles;
|
||||
}
|
||||
|
||||
// 获取远程目录下的文件总数(不下载)
|
||||
public int GetFileCount(string remoteFolder)
|
||||
{
|
||||
return GetFileCount(remoteFolder, null);
|
||||
}
|
||||
|
||||
// 获取远程目录下的文件总数,支持跳过指定路径
|
||||
public int GetFileCount(string remoteFolder, string passFilePath)
|
||||
{
|
||||
ChangeFolder(null); // 回到根目录
|
||||
if (!string.IsNullOrEmpty(remoteFolder))
|
||||
ChangeFolder(remoteFolder);
|
||||
|
||||
logManager.Log("----------------------------------Get File Count Folder:" + remoteFolder, LogLevel.INFO, this);
|
||||
|
||||
List<FtpItem> fis = List();
|
||||
if (fis == null || fis.Count == 0) return 0;
|
||||
string tempCurrentDirectory = currentDirectory;
|
||||
|
||||
string[] passFilePaths = null;
|
||||
if (!string.IsNullOrEmpty(passFilePath))
|
||||
passFilePaths = passFilePath.Split(new char[] { ';', ',' });
|
||||
if (passFilePaths != null && passFilePaths.Length > 0)
|
||||
passFilePaths = passFilePaths.Where(x => !string.IsNullOrEmpty(x)).ToArray();
|
||||
|
||||
int totalFiles = 0;
|
||||
|
||||
foreach (FtpItem fi in fis)
|
||||
{
|
||||
string tempRemoteFolder = remoteFolder + "/" + fi.Name;
|
||||
|
||||
if (passFilePaths != null && passFilePaths.Length > 0 && passFilePaths.Any(x => tempRemoteFolder.Trim().ToUpper().StartsWith(x.Trim().ToUpper() + "/")))
|
||||
{
|
||||
logManager.Log(">>>>>>>>>>>Pass Folder (counting skipped):" + tempRemoteFolder, LogLevel.INFO, this);
|
||||
continue;
|
||||
}
|
||||
|
||||
ChangeFolder(null);
|
||||
ChangeFolder(tempCurrentDirectory);
|
||||
|
||||
if (fi.IsFolder)
|
||||
{
|
||||
// 递归统计子文件夹
|
||||
totalFiles += GetFileCount(tempRemoteFolder, passFilePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
totalFiles++;
|
||||
}
|
||||
}
|
||||
|
||||
return totalFiles;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user