Пример #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)));
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
            }
        }
Пример #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}"));
        }
Пример #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}");
        }
Пример #7
0
 public SftpFileComparison(SftpFile source, SftpFile destination = null)
 {
     Source      = source;
     Destination = destination;
 }