using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Renci.SshNet.Sftp.Responses; namespace Renci.SshNet.Sftp { internal interface ISftpSession : ISubsystemSession { /// /// Gets the SFTP protocol version. /// /// /// The SFTP protocol version. /// uint ProtocolVersion { get; } /// /// Gets the remote working directory. /// /// /// The remote working directory. /// string WorkingDirectory { get; } /// /// Changes the current working directory to the specified path. /// /// The new working directory. void ChangeDirectory(string path); /// /// Resolves a given path into an absolute path on the server. /// /// The path to resolve. /// /// The absolute path. /// string GetCanonicalPath(string path); Task GetCanonicalPathAsync(string path, CancellationToken cancellationToken); /// /// Performs SSH_FXP_FSTAT request. /// /// The handle. /// if set to true returns null instead of throwing an exception. /// /// File attributes /// SftpFileAttributes RequestFStat(byte[] handle, bool nullOnError); Task RequestFStatAsync(byte[] handle, CancellationToken cancellationToken); /// /// Performs SSH_FXP_STAT request. /// /// The path. /// if set to true returns null instead of throwing an exception. /// /// File attributes. /// SftpFileAttributes RequestStat(string path, bool nullOnError = false); /// /// Performs SSH_FXP_STAT request. /// /// The path. /// The delegate that is executed when completes. /// An object that contains any additional user-defined data. /// /// A that represents the asynchronous call. /// SFtpStatAsyncResult BeginStat(string path, AsyncCallback callback, object state); /// /// Handles the end of an asynchronous read. /// /// An that represents an asynchronous call. /// /// The file attributes. /// /// is null. SftpFileAttributes EndStat(SFtpStatAsyncResult asyncResult); /// /// Performs SSH_FXP_LSTAT request. /// /// The path. /// /// File attributes /// SftpFileAttributes RequestLStat(string path); /// /// Performs SSH_FXP_LSTAT request. /// /// The path. /// The delegate that is executed when completes. /// An object that contains any additional user-defined data. /// /// A that represents the asynchronous call. /// SFtpStatAsyncResult BeginLStat(string path, AsyncCallback callback, object state); /// /// Handles the end of an asynchronous SSH_FXP_LSTAT request. /// /// An that represents an asynchronous call. /// /// The file attributes. /// /// is null. SftpFileAttributes EndLStat(SFtpStatAsyncResult asyncResult); /// /// Performs SSH_FXP_MKDIR request. /// /// The path. void RequestMkDir(string path); /// /// Performs SSH_FXP_OPEN request. /// /// The path. /// The flags. /// if set to true returns null instead of throwing an exception. /// File handle. byte[] RequestOpen(string path, Flags flags, bool nullOnError = false); Task RequestOpenAsync(string path, Flags flags, CancellationToken cancellationToken); /// /// Performs SSH_FXP_OPEN request. /// /// The path. /// The flags. /// The delegate that is executed when completes. /// An object that contains any additional user-defined data. /// /// A that represents the asynchronous call. /// SftpOpenAsyncResult BeginOpen(string path, Flags flags, AsyncCallback callback, object state); /// /// Handles the end of an asynchronous read. /// /// An that represents an asynchronous call. /// /// A array representing a file handle. /// /// /// If all available data has been read, the method completes /// immediately and returns zero bytes. /// /// is null. byte[] EndOpen(SftpOpenAsyncResult asyncResult); /// /// Performs SSH_FXP_OPENDIR request. /// /// The path. /// if set to true returns null instead of throwing an exception. /// File handle. byte[] RequestOpenDir(string path, bool nullOnError = false); Task RequestOpenDirAsync(string path, CancellationToken cancellationToken); /// /// Performs posix-rename@openssh.com extended request. /// /// The old path. /// The new path. void RequestPosixRename(string oldPath, string newPath); /// /// Performs SSH_FXP_READ request. /// /// The handle. /// The offset. /// The length. /// data array; null if EOF byte[] RequestRead(byte[] handle, ulong offset, uint length); /// /// Begins an asynchronous read using a SSH_FXP_READ request. /// /// The handle to the file to read from. /// The offset in the file to start reading from. /// The number of bytes to read. /// The delegate that is executed when completes. /// An object that contains any additional user-defined data. /// /// A that represents the asynchronous call. /// SftpReadAsyncResult BeginRead(byte[] handle, ulong offset, uint length, AsyncCallback callback, object state); /// /// Handles the end of an asynchronous read. /// /// An that represents an asynchronous call. /// /// A array representing the data read. /// /// /// If all available data has been read, the method completes /// immediately and returns zero bytes. /// /// is null. byte[] EndRead(SftpReadAsyncResult asyncResult); Task RequestReadAsync(byte[] handle, ulong offset, uint length, CancellationToken cancellationToken); /// /// Performs SSH_FXP_READDIR request. /// /// The handle. /// KeyValuePair[] RequestReadDir(byte[] handle); Task[]> RequestReadDirAsync(byte[] handle, CancellationToken cancellationToken); /// /// Performs SSH_FXP_REALPATH request. /// /// The path. /// The delegate that is executed when completes. /// An object that contains any additional user-defined data. /// /// A that represents the asynchronous call. /// SftpRealPathAsyncResult BeginRealPath(string path, AsyncCallback callback, object state); /// /// Handles the end of an asynchronous SSH_FXP_REALPATH request. /// /// An that represents an asynchronous call. /// /// The absolute path. /// /// is null. string EndRealPath(SftpRealPathAsyncResult asyncResult); /// /// Performs SSH_FXP_REMOVE request. /// /// The path. void RequestRemove(string path); Task RequestRemoveAsync(string path, CancellationToken cancellationToken); /// /// Performs SSH_FXP_RENAME request. /// /// The old path. /// The new path. void RequestRename(string oldPath, string newPath); Task RequestRenameAsync(string oldPath, string newPath, CancellationToken cancellationToken); /// /// Performs SSH_FXP_RMDIR request. /// /// The path. void RequestRmDir(string path); /// /// Performs SSH_FXP_SETSTAT request. /// /// The path. /// The attributes. void RequestSetStat(string path, SftpFileAttributes attributes); /// /// Performs statvfs@openssh.com extended request. /// /// The path. /// if set to true [null on error]. /// SftpFileSytemInformation RequestStatVfs(string path, bool nullOnError = false); Task RequestStatVfsAsync(string path, CancellationToken cancellationToken); /// /// Performs SSH_FXP_SYMLINK request. /// /// The linkpath. /// The targetpath. void RequestSymLink(string linkpath, string targetpath); /// /// Performs SSH_FXP_FSETSTAT request. /// /// The handle. /// The attributes. void RequestFSetStat(byte[] handle, SftpFileAttributes attributes); /// /// Performs SSH_FXP_WRITE request. /// /// The handle. /// The the zero-based offset (in bytes) relative to the beginning of the file that the write must start at. /// The buffer holding the data to write. /// the zero-based offset in at which to begin taking bytes to write. /// The length (in bytes) of the data to write. /// The wait event handle if needed. /// The callback to invoke when the write has completed. void RequestWrite(byte[] handle, ulong serverOffset, byte[] data, int offset, int length, AutoResetEvent wait, Action writeCompleted = null); Task RequestWriteAsync(byte[] handle, ulong serverOffset, byte[] data, int offset, int length, CancellationToken cancellationToken); /// /// Performs SSH_FXP_CLOSE request. /// /// The handle. void RequestClose(byte[] handle); Task RequestCloseAsync(byte[] handle, CancellationToken cancellationToken); /// /// Performs SSH_FXP_CLOSE request. /// /// The handle. /// The delegate that is executed when completes. /// An object that contains any additional user-defined data. /// /// A that represents the asynchronous call. /// SftpCloseAsyncResult BeginClose(byte[] handle, AsyncCallback callback, object state); /// /// Handles the end of an asynchronous close. /// /// An that represents an asynchronous call. /// is null. void EndClose(SftpCloseAsyncResult asyncResult); /// /// Calculates the optimal size of the buffer to read data from the channel. /// /// The buffer size configured on the client. /// /// The optimal size of the buffer to read data from the channel. /// uint CalculateOptimalReadLength(uint bufferSize); /// /// Calculates the optimal size of the buffer to write data on the channel. /// /// The buffer size configured on the client. /// The file handle. /// /// The optimal size of the buffer to write data on the channel. /// /// /// Currently, we do not take the remote window size into account. /// uint CalculateOptimalWriteLength(uint bufferSize, byte[] handle); ISftpFileReader CreateFileReader(byte[] handle, ISftpSession sftpSession, uint chunkSize, int maxPendingReads, long? fileSize); } }