Exemplo n.º 1
0
        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)));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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}"));
        }
Exemplo n.º 6
0
        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}");
        }
Exemplo n.º 7
0
 public SftpFileComparison(SftpFile source, SftpFile destination = null)
 {
     Source      = source;
     Destination = destination;
 }