/// <summary> /// Download a folder /// </summary> /// <param name="serverPath"></param> /// <param name="localPath"></param> /// <param name="maxThread"></param> public void DownloadFolderAsync(string serverPath, string localPath, short threadId) { string tempPath = serverPath.Substring(serverPath.LastIndexOf("/") + 1); tempPath = tempPath.Trim(); string newLocalPath = string.Format("{0}\\{1}", localPath, tempPath); lock (m_CriticalFlag) { POSFtpTranferInfo tranferInfo = new POSFtpTranferInfo(serverPath, newLocalPath, true); m_DownloadingCollection.Add(tranferInfo); } StartDownload(threadId); }
/// <summary> /// Download files in thread /// </summary> /// <param name="serverPath"></param> /// <param name="localPath"></param> /// <param name="fileNames"></param> /// <param name="maxThread"></param> public void DownloadFilesAsync(string serverPath, string localPath, string[] fileNames, int threadId) { lock (m_CriticalFlag) { string tempPath = serverPath.Substring(serverPath.LastIndexOf("/") + 1); tempPath = tempPath.Trim(); string newLocalPath = string.Format("{0}\\{1}", localPath, tempPath); foreach (string fileName in fileNames) { POSFtpTranferInfo tranferInfo = new POSFtpTranferInfo(serverPath + "/" + fileName, localPath + "\\" + fileName, false, fileName); m_DownloadingCollection.Add(tranferInfo); } } StartDownload(threadId); }
/// <summary> /// Downloading folder by a thread /// </summary> /// <param name="threadId"></param> private void InternalDownloadFolderAsyn(int threadId) { POSFtpTranferInfo tranferInfo = null; lock (m_CriticalFlag) { if (m_DownloadingCollection.Count > 0) { tranferInfo = m_DownloadingCollection[0]; m_DownloadingCollection.RemoveAt(0); } } if (tranferInfo != null && tranferInfo.IsDirectory) { UpdateDownloadList(tranferInfo); InternalDownloadFolderAsyn(threadId); } else if (tranferInfo != null) { DownloadOneFile(tranferInfo.ServerPath, tranferInfo.LocalPath, threadId); } }
private void UpdateDownloadList(POSFtpTranferInfo tranferInfo) { lock (m_CriticalFlag) { List <POSFileSystemInfo> filesInfor = ListDirectoryDetail(tranferInfo.ServerPath); //Add files to list first foreach (POSFileSystemInfo fileInfor in filesInfor) { if (fileInfor is POSFileInfo) { string newServerPath = tranferInfo.ServerPath + "/" + fileInfor.Name; string newLocalPath = tranferInfo.LocalPath + "\\" + fileInfor.Name; POSFtpTranferInfo newItem = new POSFtpTranferInfo(newServerPath, newLocalPath, false); newItem.SourceLength = fileInfor.Length; newItem.SourceLastModified = fileInfor.LastModifiedTime; m_DownloadingCollection.Add(newItem); fileInfor.FullName = newServerPath; m_allFiles.Add(fileInfor); } } //Add Folder to list foreach (POSFileSystemInfo fileInfor in filesInfor) { if (fileInfor is POSDirectoryInfor) { string newServerPath = tranferInfo.ServerPath + "/" + fileInfor.Name; string newLocalPath = tranferInfo.LocalPath + "\\" + fileInfor.Name; POSFtpTranferInfo newItem = new POSFtpTranferInfo(newServerPath, newLocalPath, true); m_DownloadingCollection.Add(newItem); } } } }