Example #1
0
        public async Task <IFile> MoveTo(IFolder destinationFolder, string newName = null)
        {
            string destinationFullName = PathUtil.CombineFragments(destinationFolder.FullName, newName ?? Name);

            await BaseFtpClient.MoveFileAsync(FullName, destinationFullName, FtpExists.Overwrite);

            return(new FtpFile(BaseFtpClient, destinationFolder, destinationFullName));
        }
Example #2
0
        private async Task <FtpListItem[]> _GetListingCore()
        {
            FtpListItem[] items = new FtpListItem[0];

            await Policy
            .Handle <FtpCommandException>()
            .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
            .ExecuteAsync(async() =>
            {
                items = await BaseFtpClient.GetListingAsync(FullName);
            });

            return(items);
        }
Example #3
0
        public async Task <Stream> GetReadStream()
        {
            string tempFileName = Path.GetTempFileName();

            await Policy
            .Handle <FtpException>()
            .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
            .ExecuteAsync(async() =>
            {
                await BaseFtpClient.DownloadFileAsync(tempFileName, FullName, true, FtpVerify.Retry | FtpVerify.Throw);
            });

            _tempFileNames.Add(tempFileName);

            return(new FileStream(tempFileName, FileMode.Open, FileAccess.Read));
        }
Example #4
0
        public async Task <Stream> GetWriteStream()
        {
            string tempFileName = Path.GetTempFileName();

            ProxyFileStream stream = new ProxyFileStream(tempFileName, FileMode.Create, async(data) =>
            {
                await Policy
                .Handle <FtpException>()
                .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
                .ExecuteAsync(async() =>
                {
                    await BaseFtpClient.UploadAsync(data, FullName, FtpExists.Overwrite, true);
                });
            });

            _tempFileNames.Add(tempFileName);

            return(stream);
        }
Example #5
0
        public async Task <IFolder> CreateOrGetFolder(string name)
        {
            string fullPath = PathUtil.CombineFragments(FullName, name);

            await Policy
            .Handle <FtpCommandException>()
            .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
            .ExecuteAsync(async() =>
            {
                bool exists = await BaseFtpClient.DirectoryExistsAsync(fullPath);

                if (!exists)
                {
                    await BaseFtpClient.CreateDirectoryAsync(fullPath);
                }
            });

            return(new FtpFolder(BaseFtpClient, fullPath));
        }
Example #6
0
 public async Task <bool> Exists()
 {
     return(await BaseFtpClient.FileExistsAsync(FullName));
 }