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