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); }
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); }
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); } }