コード例 #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
ファイル: SftpConnection.cs プロジェクト: xmxth001/SftpRelay
        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
ファイル: SftpConnection.cs プロジェクト: xmxth001/SftpRelay
        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;
 }