Ejemplo n.º 1
0
        private static async Task UploadAsync(IFtpClient client, string fileName, Stream stream, bool overwrite, CancellationToken ct)
        {
            if (!overwrite && await client.FileExistsAsync(fileName, ct))
            {
                throw new AssetAlreadyExistsException(fileName);
            }

            await client.UploadAsync(stream, fileName, overwrite?FtpExists.Overwrite : FtpExists.Skip, true, null, ct);
        }
Ejemplo n.º 2
0
        public async Task Rename(string oldFileName, string newFileName, bool overwriteExisting)
        {
            await _EnsureConnection();

            var oldFullFileName = $"/{PathHelper.Combine(_options.Path, oldFileName)}";
            var newFullFileName = $"/{PathHelper.Combine(_options.Path, newFileName)}";

            if (!overwriteExisting && await _ftpClient.FileExistsAsync(newFullFileName))
            {
                throw new InvalidOperationException($"Unable to rename {oldFileName}. The file {newFileName} already exists.");
            }

            await _ftpClient.RenameAsync(oldFullFileName, newFullFileName);
        }
Ejemplo n.º 3
0
 public async Task <bool> ExistAsync(string Path, string Filename)
 {
     try
     {
         if (await _ftpClient.FileExistsAsync(Path + Filename))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         _log.Error($"{FtpTemplateMessage("Exit", Filename, "throw exception")}", ex);
         return(false);
     }
 }