ISftpSession.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using Renci.SshNet.Sftp.Responses;
  5. namespace Renci.SshNet.Sftp
  6. {
  7. internal interface ISftpSession : ISubsystemSession
  8. {
  9. /// <summary>
  10. /// Gets the SFTP protocol version.
  11. /// </summary>
  12. /// <value>
  13. /// The SFTP protocol version.
  14. /// </value>
  15. uint ProtocolVersion { get; }
  16. /// <summary>
  17. /// Gets the remote working directory.
  18. /// </summary>
  19. /// <value>
  20. /// The remote working directory.
  21. /// </value>
  22. string WorkingDirectory { get; }
  23. /// <summary>
  24. /// Changes the current working directory to the specified path.
  25. /// </summary>
  26. /// <param name="path">The new working directory.</param>
  27. void ChangeDirectory(string path);
  28. /// <summary>
  29. /// Resolves a given path into an absolute path on the server.
  30. /// </summary>
  31. /// <param name="path">The path to resolve.</param>
  32. /// <returns>
  33. /// The absolute path.
  34. /// </returns>
  35. string GetCanonicalPath(string path);
  36. /// <summary>
  37. /// Performs SSH_FXP_FSTAT request.
  38. /// </summary>
  39. /// <param name="handle">The handle.</param>
  40. /// <returns>
  41. /// File attributes
  42. /// </returns>
  43. SftpFileAttributes RequestFStat(byte[] handle);
  44. /// <summary>
  45. /// Performs SSH_FXP_LSTAT request.
  46. /// </summary>
  47. /// <param name="path">The path.</param>
  48. /// <returns>
  49. /// File attributes
  50. /// </returns>
  51. SftpFileAttributes RequestLStat(string path);
  52. /// <summary>
  53. /// Performs SSH_FXP_MKDIR request.
  54. /// </summary>
  55. /// <param name="path">The path.</param>
  56. void RequestMkDir(string path);
  57. /// <summary>
  58. /// Performs SSH_FXP_OPEN request
  59. /// </summary>
  60. /// <param name="path">The path.</param>
  61. /// <param name="flags">The flags.</param>
  62. /// <param name="nullOnError">if set to <c>true</c> returns <c>null</c> instead of throwing an exception.</param>
  63. /// <returns>File handle.</returns>
  64. byte[] RequestOpen(string path, Flags flags, bool nullOnError = false);
  65. /// <summary>
  66. /// Performs SSH_FXP_OPENDIR request
  67. /// </summary>
  68. /// <param name="path">The path.</param>
  69. /// <param name="nullOnError">if set to <c>true</c> returns null instead of throwing an exception.</param>
  70. /// <returns>File handle.</returns>
  71. byte[] RequestOpenDir(string path, bool nullOnError = false);
  72. /// <summary>
  73. /// Performs posix-rename@openssh.com extended request.
  74. /// </summary>
  75. /// <param name="oldPath">The old path.</param>
  76. /// <param name="newPath">The new path.</param>
  77. void RequestPosixRename(string oldPath, string newPath);
  78. /// <summary>
  79. /// Performs SSH_FXP_READ request.
  80. /// </summary>
  81. /// <param name="handle">The handle.</param>
  82. /// <param name="offset">The offset.</param>
  83. /// <param name="length">The length.</param>
  84. /// <returns>data array; null if EOF</returns>
  85. byte[] RequestRead(byte[] handle, ulong offset, uint length);
  86. /// <summary>
  87. /// Performs SSH_FXP_READDIR request
  88. /// </summary>
  89. /// <param name="handle">The handle.</param>
  90. /// <returns></returns>
  91. KeyValuePair<string, SftpFileAttributes>[] RequestReadDir(byte[] handle);
  92. /// <summary>
  93. /// Performs SSH_FXP_REMOVE request.
  94. /// </summary>
  95. /// <param name="path">The path.</param>
  96. void RequestRemove(string path);
  97. /// <summary>
  98. /// Performs SSH_FXP_RENAME request.
  99. /// </summary>
  100. /// <param name="oldPath">The old path.</param>
  101. /// <param name="newPath">The new path.</param>
  102. void RequestRename(string oldPath, string newPath);
  103. /// <summary>
  104. /// Performs SSH_FXP_RMDIR request.
  105. /// </summary>
  106. /// <param name="path">The path.</param>
  107. void RequestRmDir(string path);
  108. /// <summary>
  109. /// Performs SSH_FXP_SETSTAT request.
  110. /// </summary>
  111. /// <param name="path">The path.</param>
  112. /// <param name="attributes">The attributes.</param>
  113. void RequestSetStat(string path, SftpFileAttributes attributes);
  114. /// <summary>
  115. /// Performs statvfs@openssh.com extended request.
  116. /// </summary>
  117. /// <param name="path">The path.</param>
  118. /// <param name="nullOnError">if set to <c>true</c> [null on error].</param>
  119. /// <returns></returns>
  120. SftpFileSytemInformation RequestStatVfs(string path, bool nullOnError = false);
  121. /// <summary>
  122. /// Performs SSH_FXP_SYMLINK request.
  123. /// </summary>
  124. /// <param name="linkpath">The linkpath.</param>
  125. /// <param name="targetpath">The targetpath.</param>
  126. void RequestSymLink(string linkpath, string targetpath);
  127. /// <summary>
  128. /// Performs SSH_FXP_FSETSTAT request.
  129. /// </summary>
  130. /// <param name="handle">The handle.</param>
  131. /// <param name="attributes">The attributes.</param>
  132. void RequestFSetStat(byte[] handle, SftpFileAttributes attributes);
  133. /// <summary>
  134. /// Performs SSH_FXP_WRITE request.
  135. /// </summary>
  136. /// <param name="handle">The handle.</param>
  137. /// <param name="offset">The offset.</param>
  138. /// <param name="data">The data to send.</param>
  139. #if TUNING
  140. /// <param name="length">The number of bytes of <paramref name="data"/> to send.</param>
  141. #endif
  142. /// <param name="wait">The wait event handle if needed.</param>
  143. /// <param name="writeCompleted">The callback to invoke when the write has completed.</param>
  144. void RequestWrite(byte[] handle,
  145. ulong offset,
  146. byte[] data,
  147. #if TUNING
  148. int length,
  149. #endif
  150. AutoResetEvent wait,
  151. Action<SftpStatusResponse> writeCompleted = null);
  152. /// <summary>
  153. /// Performs SSH_FXP_CLOSE request.
  154. /// </summary>
  155. /// <param name="handle">The handle.</param>
  156. void RequestClose(byte[] handle);
  157. /// <summary>
  158. /// Calculates the optimal size of the buffer to read data from the channel.
  159. /// </summary>
  160. /// <param name="bufferSize">The buffer size configured on the client.</param>
  161. /// <returns>
  162. /// The optimal size of the buffer to read data from the channel.
  163. /// </returns>
  164. uint CalculateOptimalReadLength(uint bufferSize);
  165. /// <summary>
  166. /// Calculates the optimal size of the buffer to write data on the channel.
  167. /// </summary>
  168. /// <param name="bufferSize">The buffer size configured on the client.</param>
  169. /// <param name="handle">The file handle.</param>
  170. /// <returns>
  171. /// The optimal size of the buffer to write data on the channel.
  172. /// </returns>
  173. /// <remarks>
  174. /// Currently, we do not take the remote window size into account.
  175. /// </remarks>
  176. uint CalculateOptimalWriteLength(uint bufferSize, byte[] handle);
  177. }
  178. }