예제 #1
0
        /// <summary>
        /// Add file to download/upload queue
        /// </summary>
        /// <param name="file">The remote file.</param>
        /// <param name="localBaseDir">The local base dir.</param>
        public void AddFtpFileToQueue(FtpFile file, string localBaseDir, Direction direction)
        {
            Task.Factory.StartNew(() =>
            {
                if (file.IsDirectory)
                {
                    var rootDir = file.Name;

                    foreach (var f in this.ftpClient.GetFileListingForDownload(file.Url))
                    {
                        int startIndex     = f.Url.LocalPath.IndexOf(rootDir);
                        var localDirectory = f.Url.LocalPath.Substring(startIndex, f.Url.LocalPath.Length - startIndex);

                        this.Queue.Add(new QueueEntry(NormalizeUri(localBaseDir, localDirectory), f.Url.AbsoluteUri, direction, DownloadStatus.Idle));
                    }
                }
                else
                {
                    var localDirectory = file.Url.LocalPath.Split(new string[] { file.Name }, StringSplitOptions.RemoveEmptyEntries)[1];

                    this.Queue.Add(new QueueEntry(NormalizeUri(localBaseDir, file.Url.LocalPath), file.Url.AbsoluteUri, direction, DownloadStatus.Idle));
                }

                // Save queue file
                this.SaveQueue();
            });
        }
예제 #2
0
 /// <summary>
 /// Delete file on server
 /// </summary>
 /// <param name="ftpFile">The FTP file</param>
 /// <returns></returns>
 public async Task DeleteFtpFile(FtpFile ftpFile)
 {
     if (ftpFile.IsDirectory)
     {
         await this.ftpClient.DeleteDirectoryAsync(ftpFile.Url);
     }
     else
     {
         await this.ftpClient.DeleteFileAsync(ftpFile.Url);
     }
 }