<PackageReference Include="SSH.NET" Version="2024.2.0" />

SftpSession

Represents an SFTP session.
public uint NextRequestId { get; }

Gets the next request id for sftp session.

public uint ProtocolVersion { get; }

Gets the SFTP protocol version.

public string WorkingDirectory { get; }

Gets the remote working directory.

public SftpSession(ISession session, int operationTimeout, Encoding encoding, ISftpResponseFactory sftpResponseFactory)

Initializes a new instance of the SftpSession class.

public SftpCloseAsyncResult BeginClose(byte[] handle, AsyncCallback callback, object state)

Performs SSH_FXP_CLOSE request.

public SFtpStatAsyncResult BeginLStat(string path, AsyncCallback callback, object state)

Performs SSH_FXP_LSTAT request.

public SftpOpenAsyncResult BeginOpen(string path, Flags flags, AsyncCallback callback, object state)

Performs SSH_FXP_OPEN request.

public SftpReadAsyncResult BeginRead(byte[] handle, ulong offset, uint length, AsyncCallback callback, object state)

Begins an asynchronous read using a SSH_FXP_READ request.

public SftpRealPathAsyncResult BeginRealPath(string path, AsyncCallback callback, object state)

Performs SSH_FXP_REALPATH request.

public SFtpStatAsyncResult BeginStat(string path, AsyncCallback callback, object state)

Performs SSH_FXP_STAT request.

public uint CalculateOptimalReadLength(uint bufferSize)

Calculates the optimal size of the buffer to read data from the channel.

public uint CalculateOptimalWriteLength(uint bufferSize, byte[] handle)

Calculates the optimal size of the buffer to write data on the channel.

public void ChangeDirectory(string path)

Changes the current working directory to the specified path.

public Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken = default)

Asynchronously requests to change the current working directory to the specified path.

public ISftpFileReader CreateFileReader(byte[] handle, ISftpSession sftpSession, uint chunkSize, int maxPendingReads, long? fileSize)

Creates an ISftpFileReader for reading the content of the file represented by a given handle.

public void EndClose(SftpCloseAsyncResult asyncResult)

Handles the end of an asynchronous close.

Handles the end of an asynchronous SSH_FXP_LSTAT request.

public byte[] EndOpen(SftpOpenAsyncResult asyncResult)

Handles the end of an asynchronous open.

public byte[] EndRead(SftpReadAsyncResult asyncResult)

Handles the end of an asynchronous read.

public string EndRealPath(SftpRealPathAsyncResult asyncResult)

Handles the end of an asynchronous SSH_FXP_REALPATH request.

Handles the end of an asynchronous stat.

public string GetCanonicalPath(string path)

Resolves a given path into an absolute path on the server.

public Task<string> GetCanonicalPathAsync(string path, CancellationToken cancellationToken)

Asynchronously resolves a given path into an absolute path on the server.

public void RequestClose(byte[] handle)

Performs SSH_FXP_CLOSE request.

public Task RequestCloseAsync(byte[] handle, CancellationToken cancellationToken)

Performs a SSH_FXP_CLOSE request.

public void RequestFSetStat(byte[] handle, SftpFileAttributes attributes)

Performs SSH_FXP_FSETSTAT request.

public SftpFileAttributes RequestFStat(byte[] handle, bool nullOnError)

Performs SSH_FXP_FSTAT request.

public Task<SftpFileAttributes> RequestFStatAsync(byte[] handle, CancellationToken cancellationToken)

Asynchronously performs a SSH_FXP_FSTAT request.

public SftpFileAttributes RequestLStat(string path)

Performs SSH_FXP_LSTAT request.

public Task<SftpFileAttributes> RequestLStatAsync(string path, CancellationToken cancellationToken)

Asynchronously performs SSH_FXP_LSTAT request.

public void RequestMkDir(string path)

Performs SSH_FXP_MKDIR request.

public Task RequestMkDirAsync(string path, CancellationToken cancellationToken = default)

Asynchronously performs SSH_FXP_MKDIR request.

public byte[] RequestOpen(string path, Flags flags, bool nullOnError = false)

Performs SSH_FXP_OPEN request.

public Task<byte[]> RequestOpenAsync(string path, Flags flags, CancellationToken cancellationToken)

Asynchronously performs a SSH_FXP_OPEN request.

public byte[] RequestOpenDir(string path, bool nullOnError = false)

Performs SSH_FXP_OPENDIR request.

public Task<byte[]> RequestOpenDirAsync(string path, CancellationToken cancellationToken)

Asynchronously performs a SSH_FXP_OPENDIR request.

public void RequestPosixRename(string oldPath, string newPath)

Performs posix-rename@openssh.com extended request.

public byte[] RequestRead(byte[] handle, ulong offset, uint length)

Performs SSH_FXP_READ request.

public Task<byte[]> RequestReadAsync(byte[] handle, ulong offset, uint length, CancellationToken cancellationToken)

Asynchronously performs a SSH_FXP_READ request.

public KeyValuePair<string, SftpFileAttributes>[] RequestReadDir(byte[] handle)

Performs SSH_FXP_READDIR request.

public Task<KeyValuePair<string, SftpFileAttributes>[]> RequestReadDirAsync(byte[] handle, CancellationToken cancellationToken)

Performs a SSH_FXP_READDIR request.

public void RequestRemove(string path)

Performs SSH_FXP_REMOVE request.

public Task RequestRemoveAsync(string path, CancellationToken cancellationToken)

Asynchronously performs a SSH_FXP_REMOVE request.

public void RequestRename(string oldPath, string newPath)

Performs SSH_FXP_RENAME request.

public Task RequestRenameAsync(string oldPath, string newPath, CancellationToken cancellationToken)

Asynchronously performs a SSH_FXP_RENAME request.

public void RequestRmDir(string path)

Performs SSH_FXP_RMDIR request.

public Task RequestRmDirAsync(string path, CancellationToken cancellationToken = default)

public void RequestSetStat(string path, SftpFileAttributes attributes)

Performs SSH_FXP_SETSTAT request.

public SftpFileAttributes RequestStat(string path, bool nullOnError = false)

Performs SSH_FXP_STAT request.

public SftpFileSystemInformation RequestStatVfs(string path, bool nullOnError = false)

Performs statvfs@openssh.com extended request.

public Task<SftpFileSystemInformation> RequestStatVfsAsync(string path, CancellationToken cancellationToken)

Asynchronously performs a statvfs@openssh.com extended request.

public void RequestSymLink(string linkpath, string targetpath)

Performs SSH_FXP_SYMLINK request.

public void RequestWrite(byte[] handle, ulong serverOffset, byte[] data, int offset, int length, AutoResetEvent wait, Action<SftpStatusResponse> writeCompleted = null)

Performs SSH_FXP_WRITE request.

public Task RequestWriteAsync(byte[] handle, ulong serverOffset, byte[] data, int offset, int length, CancellationToken cancellationToken)

Asynchronouly performs a SSH_FXP_WRITE request.