public Task <Stream> GetContent(SftpFile file) { var path = string.IsNullOrEmpty(file.Path) ? Path.Combine(currentDirectory.FullName, file.FileName) : Path.Combine(currentDirectory.FullName, file.Path, file.FileName); return(Task.FromResult <Stream>(File.OpenRead(path))); }
public Task DeleteFile(SftpFile file) { var path = string.IsNullOrEmpty(file.Path) ? Path.Combine(currentDirectory.FullName, file.FileName) : Path.Combine(currentDirectory.FullName, file.Path, file.FileName); File.Delete(path); return(Task.CompletedTask); }
private bool FileHasChanged(SftpFile sourceFile, SftpFile destinationFile) { if (destination.SetAttributes) { return(destinationFile.Size != sourceFile.Size || sourceFile.LastModified != destinationFile.LastModified); } return(destinationFile.Size != sourceFile.Size || sourceFile.LastModified > destinationFile.LastModified); }
public async Task CreateFile(SftpFile file, Stream fileContent) { var path = string.IsNullOrEmpty(file.Path) ? Path.Combine(currentDirectory.FullName, file.FileName) : Path.Combine(currentDirectory.FullName, file.Path, file.FileName); using (var writeStream = File.OpenWrite(path)) await fileContent.CopyToAsync(writeStream); if (this.setAttributes) { File.SetLastWriteTimeUtc(path, file.LastModified.UtcDateTime); } }
public async Task <Stream> GetContent(SftpFile file) { if (this.client == null) { throw new InvalidOperationException($"Not connected to {service.HostName}:{service.Port}"); } var subPath = string.IsNullOrEmpty(file.Path) ? file.FileName : $"{file.Path}/{file.FileName}"; Trace.TraceInformation($"Getting content of {directory}/{subPath} ({file.Size / 1024.0:n1}kb) from {service.HostName}:{service.Port}"); return(await this.client.OpenReadAsync($"{directory}/{subPath}")); }
public async Task DeleteFile(SftpFile file) { if (this.client == null) { throw new InvalidOperationException($"Not connected to {service.HostName}:{service.Port}"); } var subPath = string.IsNullOrEmpty(file.Path) ? file.FileName : $"{file.Path}/{file.FileName}"; Trace.TraceInformation($"Deleting file {directory}/{subPath} from {service.HostName}:{service.Port}"); await this.client.DeleteFileAsync($"{directory}/{subPath}"); }
public SftpFileComparison(SftpFile source, SftpFile destination = null) { Source = source; Destination = destination; }