ISftpClient.cs 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using Renci.SshNet.Common;
  8. using Renci.SshNet.Sftp;
  9. namespace Renci.SshNet
  10. {
  11. /// <summary>
  12. /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
  13. /// </summary>
  14. public interface ISftpClient : IBaseClient, IDisposable
  15. {
  16. /// <summary>
  17. /// Gets or sets the maximum size of the buffer in bytes.
  18. /// </summary>
  19. /// <value>
  20. /// The size of the buffer. The default buffer size is 32768 bytes (32 KB).
  21. /// </value>
  22. /// <remarks>
  23. /// <para>
  24. /// For write operations, this limits the size of the payload for
  25. /// individual SSH_FXP_WRITE messages. The actual size is always
  26. /// capped at the maximum packet size supported by the peer
  27. /// (minus the size of protocol fields).
  28. /// </para>
  29. /// <para>
  30. /// For read operations, this controls the size of the payload which
  31. /// is requested from the peer in a SSH_FXP_READ message. The peer
  32. /// will send the requested number of bytes in a SSH_FXP_DATA message,
  33. /// possibly split over multiple SSH_MSG_CHANNEL_DATA messages.
  34. /// </para>
  35. /// <para>
  36. /// To optimize the size of the SSH packets sent by the peer,
  37. /// the actual requested size will take into account the size of the
  38. /// SSH_FXP_DATA protocol fields.
  39. /// </para>
  40. /// <para>
  41. /// The size of the each individual SSH_FXP_DATA message is limited to the
  42. /// local maximum packet size of the channel, which is set to <c>64 KB</c>
  43. /// for SSH.NET. However, the peer can limit this even further.
  44. /// </para>
  45. /// </remarks>
  46. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  47. uint BufferSize { get; set; }
  48. /// <summary>
  49. /// Gets or sets the operation timeout.
  50. /// </summary>
  51. /// <value>
  52. /// The timeout to wait until an operation completes. The default value is negative
  53. /// one (-1) milliseconds, which indicates an infinite timeout period.
  54. /// </value>
  55. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  56. /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> represents a value that is less than -1 or greater than <see cref="int.MaxValue"/> milliseconds.</exception>
  57. TimeSpan OperationTimeout { get; set; }
  58. /// <summary>
  59. /// Gets sftp protocol version.
  60. /// </summary>
  61. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  62. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  63. int ProtocolVersion { get; }
  64. /// <summary>
  65. /// Gets remote working directory.
  66. /// </summary>
  67. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  68. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  69. string WorkingDirectory { get; }
  70. /// <summary>
  71. /// Appends lines to a file, creating the file if it does not already exist.
  72. /// </summary>
  73. /// <param name="path">The file to append the lines to. The file is created if it does not already exist.</param>
  74. /// <param name="contents">The lines to append to the file.</param>
  75. /// <exception cref="ArgumentNullException"><paramref name="path"/> is<b>null</b> <para>-or-</para> <paramref name="contents"/> is <b>null</b>.</exception>
  76. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  77. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  78. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  79. /// <remarks>
  80. /// The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM)
  81. /// </remarks>
  82. void AppendAllLines(string path, IEnumerable<string> contents);
  83. /// <summary>
  84. /// Appends lines to a file by using a specified encoding, creating the file if it does not already exist.
  85. /// </summary>
  86. /// <param name="path">The file to append the lines to. The file is created if it does not already exist.</param>
  87. /// <param name="contents">The lines to append to the file.</param>
  88. /// <param name="encoding">The character encoding to use.</param>
  89. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>. <para>-or-</para> <paramref name="contents"/> is <b>null</b>. <para>-or-</para> <paramref name="encoding"/> is <b>null</b>.</exception>
  90. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  91. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  92. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  93. void AppendAllLines(string path, IEnumerable<string> contents, Encoding encoding);
  94. /// <summary>
  95. /// Appends the specified string to the file, creating the file if it does not already exist.
  96. /// </summary>
  97. /// <param name="path">The file to append the specified string to.</param>
  98. /// <param name="contents">The string to append to the file.</param>
  99. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>. <para>-or-</para> <paramref name="contents"/> is <b>null</b>.</exception>
  100. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  101. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  102. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  103. /// <remarks>
  104. /// The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
  105. /// </remarks>
  106. void AppendAllText(string path, string contents);
  107. /// <summary>
  108. /// Appends the specified string to the file, creating the file if it does not already exist.
  109. /// </summary>
  110. /// <param name="path">The file to append the specified string to.</param>
  111. /// <param name="contents">The string to append to the file.</param>
  112. /// <param name="encoding">The character encoding to use.</param>
  113. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>. <para>-or-</para> <paramref name="contents"/> is <b>null</b>. <para>-or-</para> <paramref name="encoding"/> is <b>null</b>.</exception>
  114. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  115. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  116. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  117. void AppendAllText(string path, string contents, Encoding encoding);
  118. /// <summary>
  119. /// Creates a <see cref="StreamWriter"/> that appends UTF-8 encoded text to the specified file,
  120. /// creating the file if it does not already exist.
  121. /// </summary>
  122. /// <param name="path">The path to the file to append to.</param>
  123. /// <returns>
  124. /// A <see cref="StreamWriter"/> that appends text to a file using UTF-8 encoding without a
  125. /// Byte-Order Mark (BOM).
  126. /// </returns>
  127. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  128. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  129. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  130. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  131. StreamWriter AppendText(string path);
  132. /// <summary>
  133. /// Creates a <see cref="StreamWriter"/> that appends text to a file using the specified
  134. /// encoding, creating the file if it does not already exist.
  135. /// </summary>
  136. /// <param name="path">The path to the file to append to.</param>
  137. /// <param name="encoding">The character encoding to use.</param>
  138. /// <returns>
  139. /// A <see cref="StreamWriter"/> that appends text to a file using the specified encoding.
  140. /// </returns>
  141. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>. <para>-or-</para> <paramref name="encoding"/> is <b>null</b>.</exception>
  142. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  143. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  144. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  145. StreamWriter AppendText(string path, Encoding encoding);
  146. /// <summary>
  147. /// Begins an asynchronous file downloading into the stream.
  148. /// </summary>
  149. /// <param name="path">The path.</param>
  150. /// <param name="output">The output.</param>
  151. /// <returns>
  152. /// An <see cref="IAsyncResult" /> that references the asynchronous operation.
  153. /// </returns>
  154. /// <exception cref="ArgumentNullException"><paramref name="output" /> is <b>null</b>.</exception>
  155. /// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains only whitespace characters.</exception>
  156. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  157. /// <exception cref="SftpPermissionDeniedException">Permission to perform the operation was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  158. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  159. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  160. /// <remarks>
  161. /// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
  162. /// </remarks>
  163. IAsyncResult BeginDownloadFile(string path, Stream output);
  164. /// <summary>
  165. /// Begins an asynchronous file downloading into the stream.
  166. /// </summary>
  167. /// <param name="path">The path.</param>
  168. /// <param name="output">The output.</param>
  169. /// <param name="asyncCallback">The method to be called when the asynchronous write operation is completed.</param>
  170. /// <returns>
  171. /// An <see cref="IAsyncResult" /> that references the asynchronous operation.
  172. /// </returns>
  173. /// <exception cref="ArgumentNullException"><paramref name="output" /> is <b>null</b>.</exception>
  174. /// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains only whitespace characters.</exception>
  175. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  176. /// <exception cref="SftpPermissionDeniedException">Permission to perform the operation was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  177. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  178. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  179. /// <remarks>
  180. /// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
  181. /// </remarks>
  182. IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback asyncCallback);
  183. /// <summary>
  184. /// Begins an asynchronous file downloading into the stream.
  185. /// </summary>
  186. /// <param name="path">The path.</param>
  187. /// <param name="output">The output.</param>
  188. /// <param name="asyncCallback">The method to be called when the asynchronous write operation is completed.</param>
  189. /// <param name="state">A user-provided object that distinguishes this particular asynchronous write request from other requests.</param>
  190. /// <param name="downloadCallback">The download callback.</param>
  191. /// <returns>
  192. /// An <see cref="IAsyncResult" /> that references the asynchronous operation.
  193. /// </returns>
  194. /// <exception cref="ArgumentNullException"><paramref name="output" /> is <b>null</b>.</exception>
  195. /// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains only whitespace characters.</exception>
  196. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  197. /// <remarks>
  198. /// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
  199. /// </remarks>
  200. IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback asyncCallback, object state, Action<ulong> downloadCallback = null);
  201. /// <summary>
  202. /// Begins an asynchronous operation of retrieving list of files in remote directory.
  203. /// </summary>
  204. /// <param name="path">The path.</param>
  205. /// <param name="asyncCallback">The method to be called when the asynchronous write operation is completed.</param>
  206. /// <param name="state">A user-provided object that distinguishes this particular asynchronous write request from other requests.</param>
  207. /// <param name="listCallback">The list callback.</param>
  208. /// <returns>
  209. /// An <see cref="IAsyncResult" /> that references the asynchronous operation.
  210. /// </returns>
  211. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  212. IAsyncResult BeginListDirectory(string path, AsyncCallback asyncCallback, object state, Action<int> listCallback = null);
  213. /// <summary>
  214. /// Begins the synchronize directories.
  215. /// </summary>
  216. /// <param name="sourcePath">The source path.</param>
  217. /// <param name="destinationPath">The destination path.</param>
  218. /// <param name="searchPattern">The search pattern.</param>
  219. /// <param name="asyncCallback">The async callback.</param>
  220. /// <param name="state">The state.</param>
  221. /// <returns>
  222. /// An <see cref="IAsyncResult" /> that represents the asynchronous directory synchronization.
  223. /// </returns>
  224. /// <exception cref="ArgumentNullException"><paramref name="sourcePath"/> is <c>null</c>.</exception>
  225. /// <exception cref="ArgumentException"><paramref name="destinationPath"/> is <c>null</c> or contains only whitespace.</exception>
  226. /// <exception cref="SshException">If a problem occurs while copying the file</exception>
  227. IAsyncResult BeginSynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern, AsyncCallback asyncCallback, object state);
  228. /// <summary>
  229. /// Begins an asynchronous uploading the stream into remote file.
  230. /// </summary>
  231. /// <param name="input">Data input stream.</param>
  232. /// <param name="path">Remote file path.</param>
  233. /// <returns>
  234. /// An <see cref="IAsyncResult" /> that references the asynchronous operation.
  235. /// </returns>
  236. /// <exception cref="ArgumentNullException"><paramref name="input" /> is <b>null</b>.</exception>
  237. /// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains only whitespace characters.</exception>
  238. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  239. /// <exception cref="SftpPermissionDeniedException">Permission to list the contents of the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  240. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  241. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  242. /// <remarks>
  243. /// <para>
  244. /// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
  245. /// </para>
  246. /// <para>
  247. /// If the remote file already exists, it is overwritten and truncated.
  248. /// </para>
  249. /// </remarks>
  250. IAsyncResult BeginUploadFile(Stream input, string path);
  251. /// <summary>
  252. /// Begins an asynchronous uploading the stream into remote file.
  253. /// </summary>
  254. /// <param name="input">Data input stream.</param>
  255. /// <param name="path">Remote file path.</param>
  256. /// <param name="asyncCallback">The method to be called when the asynchronous write operation is completed.</param>
  257. /// <returns>
  258. /// An <see cref="IAsyncResult" /> that references the asynchronous operation.
  259. /// </returns>
  260. /// <exception cref="ArgumentNullException"><paramref name="input" /> is <b>null</b>.</exception>
  261. /// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains only whitespace characters.</exception>
  262. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  263. /// <exception cref="SftpPermissionDeniedException">Permission to list the contents of the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  264. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  265. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  266. /// <remarks>
  267. /// <para>
  268. /// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
  269. /// </para>
  270. /// <para>
  271. /// If the remote file already exists, it is overwritten and truncated.
  272. /// </para>
  273. /// </remarks>
  274. IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback asyncCallback);
  275. /// <summary>
  276. /// Begins an asynchronous uploading the stream into remote file.
  277. /// </summary>
  278. /// <param name="input">Data input stream.</param>
  279. /// <param name="path">Remote file path.</param>
  280. /// <param name="asyncCallback">The method to be called when the asynchronous write operation is completed.</param>
  281. /// <param name="state">A user-provided object that distinguishes this particular asynchronous write request from other requests.</param>
  282. /// <param name="uploadCallback">The upload callback.</param>
  283. /// <returns>
  284. /// An <see cref="IAsyncResult" /> that references the asynchronous operation.
  285. /// </returns>
  286. /// <exception cref="ArgumentNullException"><paramref name="input" /> is <b>null</b>.</exception>
  287. /// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains only whitespace characters.</exception>
  288. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  289. /// <exception cref="SftpPermissionDeniedException">Permission to list the contents of the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  290. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  291. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  292. /// <remarks>
  293. /// <para>
  294. /// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
  295. /// </para>
  296. /// <para>
  297. /// If the remote file already exists, it is overwritten and truncated.
  298. /// </para>
  299. /// </remarks>
  300. IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback asyncCallback, object state, Action<ulong> uploadCallback = null);
  301. /// <summary>
  302. /// Begins an asynchronous uploading the stream into remote file.
  303. /// </summary>
  304. /// <param name="input">Data input stream.</param>
  305. /// <param name="path">Remote file path.</param>
  306. /// <param name="canOverride">Specified whether an existing file can be overwritten.</param>
  307. /// <param name="asyncCallback">The method to be called when the asynchronous write operation is completed.</param>
  308. /// <param name="state">A user-provided object that distinguishes this particular asynchronous write request from other requests.</param>
  309. /// <param name="uploadCallback">The upload callback.</param>
  310. /// <returns>
  311. /// An <see cref="IAsyncResult" /> that references the asynchronous operation.
  312. /// </returns>
  313. /// <exception cref="ArgumentNullException"><paramref name="input" /> is <b>null</b>.</exception>
  314. /// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains only whitespace characters.</exception>
  315. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  316. /// <remarks>
  317. /// <para>
  318. /// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
  319. /// </para>
  320. /// <para>
  321. /// When <paramref name="path"/> refers to an existing file, set <paramref name="canOverride"/> to <c>true</c> to overwrite and truncate that file.
  322. /// If <paramref name="canOverride"/> is <c>false</c>, the upload will fail and <see cref="SftpClient.EndUploadFile(IAsyncResult)"/> will throw an
  323. /// <see cref="SshException"/>.
  324. /// </para>
  325. /// </remarks>
  326. IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride, AsyncCallback asyncCallback, object state, Action<ulong> uploadCallback = null);
  327. /// <summary>
  328. /// Changes remote directory to path.
  329. /// </summary>
  330. /// <param name="path">New directory path.</param>
  331. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  332. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  333. /// <exception cref="SftpPermissionDeniedException">Permission to change directory denied by remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  334. /// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
  335. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message"/> is the message from the remote host.</exception>
  336. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  337. void ChangeDirectory(string path);
  338. /// <summary>
  339. /// Changes permissions of file(s) to specified mode.
  340. /// </summary>
  341. /// <param name="path">File(s) path, may match multiple files.</param>
  342. /// <param name="mode">The mode.</param>
  343. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  344. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  345. /// <exception cref="SftpPermissionDeniedException">Permission to change permission on the path(s) was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  346. /// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
  347. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message"/> is the message from the remote host.</exception>
  348. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  349. void ChangePermissions(string path, short mode);
  350. /// <summary>
  351. /// Creates or overwrites a file in the specified path.
  352. /// </summary>
  353. /// <param name="path">The path and name of the file to create.</param>
  354. /// <returns>
  355. /// A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path.
  356. /// </returns>
  357. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  358. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  359. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  360. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  361. /// <remarks>
  362. /// If the target file already exists, it is first truncated to zero bytes.
  363. /// </remarks>
  364. SftpFileStream Create(string path);
  365. /// <summary>
  366. /// Creates or overwrites the specified file.
  367. /// </summary>
  368. /// <param name="path">The path and name of the file to create.</param>
  369. /// <param name="bufferSize">The maximum number of bytes buffered for reads and writes to the file.</param>
  370. /// <returns>
  371. /// A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path.
  372. /// </returns>
  373. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  374. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  375. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  376. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  377. /// <remarks>
  378. /// If the target file already exists, it is first truncated to zero bytes.
  379. /// </remarks>
  380. SftpFileStream Create(string path, int bufferSize);
  381. /// <summary>
  382. /// Creates remote directory specified by path.
  383. /// </summary>
  384. /// <param name="path">Directory path to create.</param>
  385. /// <exception cref="ArgumentException"><paramref name="path"/> is <b>null</b> or contains only whitespace characters.</exception>
  386. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  387. /// <exception cref="SftpPermissionDeniedException">Permission to create the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  388. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message"/> is the message from the remote host.</exception>
  389. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  390. void CreateDirectory(string path);
  391. /// <summary>
  392. /// Creates or opens a file for writing UTF-8 encoded text.
  393. /// </summary>
  394. /// <param name="path">The file to be opened for writing.</param>
  395. /// <returns>
  396. /// A <see cref="StreamWriter"/> that writes text to a file using UTF-8 encoding without
  397. /// a Byte-Order Mark (BOM).
  398. /// </returns>
  399. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  400. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  401. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  402. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  403. /// <remarks>
  404. /// <para>
  405. /// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
  406. /// </para>
  407. /// <para>
  408. /// If the target file does not exist, it is created.
  409. /// </para>
  410. /// </remarks>
  411. StreamWriter CreateText(string path);
  412. /// <summary>
  413. /// Creates or opens a file for writing text using the specified encoding.
  414. /// </summary>
  415. /// <param name="path">The file to be opened for writing.</param>
  416. /// <param name="encoding">The character encoding to use.</param>
  417. /// <returns>
  418. /// A <see cref="StreamWriter"/> that writes to a file using the specified encoding.
  419. /// </returns>
  420. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  421. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  422. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  423. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  424. /// <remarks>
  425. /// <para>
  426. /// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
  427. /// </para>
  428. /// <para>
  429. /// If the target file does not exist, it is created.
  430. /// </para>
  431. /// </remarks>
  432. StreamWriter CreateText(string path, Encoding encoding);
  433. /// <summary>
  434. /// Deletes the specified file or directory.
  435. /// </summary>
  436. /// <param name="path">The name of the file or directory to be deleted. Wildcard characters are not supported.</param>
  437. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  438. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  439. /// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
  440. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  441. void Delete(string path);
  442. /// <summary>
  443. /// Deletes remote directory specified by path.
  444. /// </summary>
  445. /// <param name="path">Directory to be deleted path.</param>
  446. /// <exception cref="ArgumentException"><paramref name="path"/> is <b>null</b> or contains only whitespace characters.</exception>
  447. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  448. /// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
  449. /// <exception cref="SftpPermissionDeniedException">Permission to delete the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  450. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message"/> is the message from the remote host.</exception>
  451. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  452. void DeleteDirectory(string path);
  453. /// <summary>
  454. /// Deletes remote file specified by path.
  455. /// </summary>
  456. /// <param name="path">File to be deleted path.</param>
  457. /// <exception cref="ArgumentException"><paramref name="path"/> is <b>null</b> or contains only whitespace characters.</exception>
  458. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  459. /// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
  460. /// <exception cref="SftpPermissionDeniedException">Permission to delete the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  461. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message"/> is the message from the remote host.</exception>
  462. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  463. void DeleteFile(string path);
  464. /// <summary>
  465. /// Asynchronously deletes remote file specified by path.
  466. /// </summary>
  467. /// <param name="path">File to be deleted path.</param>
  468. /// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
  469. /// <returns>A <see cref="Task"/> that represents the asynchronous delete operation.</returns>
  470. /// <exception cref="ArgumentException"><paramref name="path"/> is <b>null</b> or contains only whitespace characters.</exception>
  471. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  472. /// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
  473. /// <exception cref="SftpPermissionDeniedException">Permission to delete the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  474. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message"/> is the message from the remote host.</exception>
  475. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  476. Task DeleteFileAsync(string path, CancellationToken cancellationToken);
  477. /// <summary>
  478. /// Downloads remote file specified by the path into the stream.
  479. /// </summary>
  480. /// <param name="path">File to download.</param>
  481. /// <param name="output">Stream to write the file into.</param>
  482. /// <param name="downloadCallback">The download callback.</param>
  483. /// <exception cref="ArgumentNullException"><paramref name="output" /> is <b>null</b>.</exception>
  484. /// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains only whitespace characters.</exception>
  485. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  486. /// <exception cref="SftpPermissionDeniedException">Permission to perform the operation was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  487. /// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>///
  488. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  489. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  490. /// <remarks>
  491. /// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
  492. /// </remarks>
  493. void DownloadFile(string path, Stream output, Action<ulong> downloadCallback = null);
  494. /// <summary>
  495. /// Ends an asynchronous file downloading into the stream.
  496. /// </summary>
  497. /// <param name="asyncResult">The pending asynchronous SFTP request.</param>
  498. /// <exception cref="ArgumentException">The <see cref="IAsyncResult"/> object did not come from the corresponding async method on this type.<para>-or-</para><see cref="SftpClient.EndDownloadFile(IAsyncResult)"/> was called multiple times with the same <see cref="IAsyncResult"/>.</exception>
  499. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  500. /// <exception cref="SftpPermissionDeniedException">Permission to perform the operation was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  501. /// <exception cref="SftpPathNotFoundException">The path was not found on the remote host.</exception>
  502. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  503. void EndDownloadFile(IAsyncResult asyncResult);
  504. /// <summary>
  505. /// Ends an asynchronous operation of retrieving list of files in remote directory.
  506. /// </summary>
  507. /// <param name="asyncResult">The pending asynchronous SFTP request.</param>
  508. /// <returns>
  509. /// A list of files.
  510. /// </returns>
  511. /// <exception cref="ArgumentException">The <see cref="IAsyncResult"/> object did not come from the corresponding async method on this type.<para>-or-</para><see cref="SftpClient.EndListDirectory(IAsyncResult)"/> was called multiple times with the same <see cref="IAsyncResult"/>.</exception>
  512. IEnumerable<ISftpFile> EndListDirectory(IAsyncResult asyncResult);
  513. /// <summary>
  514. /// Ends the synchronize directories.
  515. /// </summary>
  516. /// <param name="asyncResult">The async result.</param>
  517. /// <returns>
  518. /// A list of uploaded files.
  519. /// </returns>
  520. /// <exception cref="ArgumentException">The <see cref="IAsyncResult"/> object did not come from the corresponding async method on this type.<para>-or-</para><see cref="SftpClient.EndSynchronizeDirectories(IAsyncResult)"/> was called multiple times with the same <see cref="IAsyncResult"/>.</exception>
  521. /// <exception cref="SftpPathNotFoundException">The destination path was not found on the remote host.</exception>
  522. IEnumerable<FileInfo> EndSynchronizeDirectories(IAsyncResult asyncResult);
  523. /// <summary>
  524. /// Ends an asynchronous uploading the stream into remote file.
  525. /// </summary>
  526. /// <param name="asyncResult">The pending asynchronous SFTP request.</param>
  527. /// <exception cref="ArgumentException">The <see cref="IAsyncResult"/> object did not come from the corresponding async method on this type.<para>-or-</para><see cref="SftpClient.EndUploadFile(IAsyncResult)"/> was called multiple times with the same <see cref="IAsyncResult"/>.</exception>
  528. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  529. /// <exception cref="SftpPathNotFoundException">The directory of the file was not found on the remote host.</exception>
  530. /// <exception cref="SftpPermissionDeniedException">Permission to upload the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  531. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  532. void EndUploadFile(IAsyncResult asyncResult);
  533. /// <summary>
  534. /// Checks whether file or directory exists;
  535. /// </summary>
  536. /// <param name="path">The path.</param>
  537. /// <returns>
  538. /// <c>true</c> if directory or file exists; otherwise <c>false</c>.
  539. /// </returns>
  540. /// <exception cref="ArgumentException"><paramref name="path"/> is <b>null</b> or contains only whitespace characters.</exception>
  541. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  542. /// <exception cref="SftpPermissionDeniedException">Permission to perform the operation was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  543. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message"/> is the message from the remote host.</exception>
  544. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  545. bool Exists(string path);
  546. /// <summary>
  547. /// Gets reference to remote file or directory.
  548. /// </summary>
  549. /// <param name="path">The path.</param>
  550. /// <returns>
  551. /// A reference to <see cref="ISftpFile"/> file object.
  552. /// </returns>
  553. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  554. /// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
  555. /// <exception cref="ArgumentNullException"><paramref name="path" /> is <b>null</b>.</exception>
  556. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  557. ISftpFile Get(string path);
  558. /// <summary>
  559. /// Gets the <see cref="SftpFileAttributes"/> of the file on the path.
  560. /// </summary>
  561. /// <param name="path">The path to the file.</param>
  562. /// <returns>
  563. /// The <see cref="SftpFileAttributes"/> of the file on the path.
  564. /// </returns>
  565. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  566. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  567. /// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
  568. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  569. SftpFileAttributes GetAttributes(string path);
  570. /// <summary>
  571. /// Returns the date and time the specified file or directory was last accessed.
  572. /// </summary>
  573. /// <param name="path">The file or directory for which to obtain access date and time information.</param>
  574. /// <returns>
  575. /// A <see cref="DateTime"/> structure set to the date and time that the specified file or directory was last accessed.
  576. /// This value is expressed in local time.
  577. /// </returns>
  578. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  579. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  580. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  581. DateTime GetLastAccessTime(string path);
  582. /// <summary>
  583. /// Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last accessed.
  584. /// </summary>
  585. /// <param name="path">The file or directory for which to obtain access date and time information.</param>
  586. /// <returns>
  587. /// A <see cref="DateTime"/> structure set to the date and time that the specified file or directory was last accessed.
  588. /// This value is expressed in UTC time.
  589. /// </returns>
  590. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  591. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  592. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  593. DateTime GetLastAccessTimeUtc(string path);
  594. /// <summary>
  595. /// Returns the date and time the specified file or directory was last written to.
  596. /// </summary>
  597. /// <param name="path">The file or directory for which to obtain write date and time information.</param>
  598. /// <returns>
  599. /// A <see cref="DateTime"/> structure set to the date and time that the specified file or directory was last written to.
  600. /// This value is expressed in local time.
  601. /// </returns>
  602. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  603. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  604. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  605. DateTime GetLastWriteTime(string path);
  606. /// <summary>
  607. /// Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last written to.
  608. /// </summary>
  609. /// <param name="path">The file or directory for which to obtain write date and time information.</param>
  610. /// <returns>
  611. /// A <see cref="DateTime"/> structure set to the date and time that the specified file or directory was last written to.
  612. /// This value is expressed in UTC time.
  613. /// </returns>
  614. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  615. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  616. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  617. DateTime GetLastWriteTimeUtc(string path);
  618. /// <summary>
  619. /// Gets status using statvfs@openssh.com request.
  620. /// </summary>
  621. /// <param name="path">The path.</param>
  622. /// <returns>
  623. /// A <see cref="SftpFileSytemInformation"/> instance that contains file status information.
  624. /// </returns>
  625. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  626. /// <exception cref="ArgumentNullException"><paramref name="path" /> is <b>null</b>.</exception>
  627. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  628. SftpFileSytemInformation GetStatus(string path);
  629. /// <summary>
  630. /// Asynchronously gets status using statvfs@openssh.com request.
  631. /// </summary>
  632. /// <param name="path">The path.</param>
  633. /// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
  634. /// <returns>
  635. /// A <see cref="Task{SftpFileSytemInformation}"/> that represents the status operation.
  636. /// The task result contains the <see cref="SftpFileSytemInformation"/> instance that contains file status information.
  637. /// </returns>
  638. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  639. /// <exception cref="ArgumentNullException"><paramref name="path" /> is <b>null</b>.</exception>
  640. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  641. Task<SftpFileSytemInformation> GetStatusAsync(string path, CancellationToken cancellationToken);
  642. /// <summary>
  643. /// Retrieves list of files in remote directory.
  644. /// </summary>
  645. /// <param name="path">The path.</param>
  646. /// <param name="listCallback">The list callback.</param>
  647. /// <returns>
  648. /// A list of files.
  649. /// </returns>
  650. /// <exception cref="ArgumentNullException"><paramref name="path" /> is <b>null</b>.</exception>
  651. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  652. /// <exception cref="SftpPermissionDeniedException">Permission to list the contents of the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  653. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  654. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  655. IEnumerable<ISftpFile> ListDirectory(string path, Action<int> listCallback = null);
  656. /// <summary>
  657. /// Asynchronously enumerates the files in remote directory.
  658. /// </summary>
  659. /// <param name="path">The path.</param>
  660. /// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
  661. /// <returns>
  662. /// An <see cref="IAsyncEnumerable{T}"/> of <see cref="ISftpFile"/> that represents the asynchronous enumeration operation.
  663. /// The enumeration contains an async stream of <see cref="ISftpFile"/> for the files in the directory specified by <paramref name="path" />.
  664. /// </returns>
  665. /// <exception cref="ArgumentNullException"><paramref name="path" /> is <b>null</b>.</exception>
  666. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  667. /// <exception cref="SftpPermissionDeniedException">Permission to list the contents of the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  668. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  669. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  670. IAsyncEnumerable<ISftpFile> ListDirectoryAsync(string path, CancellationToken cancellationToken);
  671. /// <summary>
  672. /// Opens a <see cref="SftpFileStream"/> on the specified path with read/write access.
  673. /// </summary>
  674. /// <param name="path">The file to open.</param>
  675. /// <param name="mode">A <see cref="FileMode"/> value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
  676. /// <returns>
  677. /// An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and read/write access.
  678. /// </returns>
  679. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  680. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  681. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  682. SftpFileStream Open(string path, FileMode mode);
  683. /// <summary>
  684. /// Opens a <see cref="SftpFileStream"/> on the specified path, with the specified mode and access.
  685. /// </summary>
  686. /// <param name="path">The file to open.</param>
  687. /// <param name="mode">A <see cref="FileMode"/> value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
  688. /// <param name="access">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file.</param>
  689. /// <returns>
  690. /// An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.
  691. /// </returns>
  692. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  693. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  694. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  695. SftpFileStream Open(string path, FileMode mode, FileAccess access);
  696. /// <summary>
  697. /// Asynchronously opens a <see cref="SftpFileStream"/> on the specified path, with the specified mode and access.
  698. /// </summary>
  699. /// <param name="path">The file to open.</param>
  700. /// <param name="mode">A <see cref="FileMode"/> value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
  701. /// <param name="access">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file.</param>
  702. /// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
  703. /// <returns>
  704. /// A <see cref="Task{SftpFileStream}"/> that represents the asynchronous open operation.
  705. /// The task result contains the <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.
  706. /// </returns>
  707. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  708. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  709. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  710. Task<SftpFileStream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken);
  711. /// <summary>
  712. /// Opens an existing file for reading.
  713. /// </summary>
  714. /// <param name="path">The file to be opened for reading.</param>
  715. /// <returns>
  716. /// A read-only <see cref="SftpFileStream"/> on the specified path.
  717. /// </returns>
  718. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  719. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  720. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  721. SftpFileStream OpenRead(string path);
  722. /// <summary>
  723. /// Opens an existing UTF-8 encoded text file for reading.
  724. /// </summary>
  725. /// <param name="path">The file to be opened for reading.</param>
  726. /// <returns>
  727. /// A <see cref="StreamReader"/> on the specified path.
  728. /// </returns>
  729. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  730. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  731. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  732. StreamReader OpenText(string path);
  733. /// <summary>
  734. /// Opens a file for writing.
  735. /// </summary>
  736. /// <param name="path">The file to be opened for writing.</param>
  737. /// <returns>
  738. /// An unshared <see cref="SftpFileStream"/> object on the specified path with <see cref="FileAccess.Write"/> access.
  739. /// </returns>
  740. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  741. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  742. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  743. /// <remarks>
  744. /// If the file does not exist, it is created.
  745. /// </remarks>
  746. SftpFileStream OpenWrite(string path);
  747. /// <summary>
  748. /// Opens a binary file, reads the contents of the file into a byte array, and closes the file.
  749. /// </summary>
  750. /// <param name="path">The file to open for reading.</param>
  751. /// <returns>
  752. /// A byte array containing the contents of the file.
  753. /// </returns>
  754. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  755. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  756. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  757. byte[] ReadAllBytes(string path);
  758. /// <summary>
  759. /// Opens a text file, reads all lines of the file using UTF-8 encoding, and closes the file.
  760. /// </summary>
  761. /// <param name="path">The file to open for reading.</param>
  762. /// <returns>
  763. /// A string array containing all lines of the file.
  764. /// </returns>
  765. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  766. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  767. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  768. string[] ReadAllLines(string path);
  769. /// <summary>
  770. /// Opens a file, reads all lines of the file with the specified encoding, and closes the file.
  771. /// </summary>
  772. /// <param name="path">The file to open for reading.</param>
  773. /// <param name="encoding">The encoding applied to the contents of the file.</param>
  774. /// <returns>
  775. /// A string array containing all lines of the file.
  776. /// </returns>
  777. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  778. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  779. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  780. string[] ReadAllLines(string path, Encoding encoding);
  781. /// <summary>
  782. /// Opens a text file, reads all lines of the file with the UTF-8 encoding, and closes the file.
  783. /// </summary>
  784. /// <param name="path">The file to open for reading.</param>
  785. /// <returns>
  786. /// A string containing all lines of the file.
  787. /// </returns>
  788. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  789. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  790. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  791. string ReadAllText(string path);
  792. /// <summary>
  793. /// Opens a file, reads all lines of the file with the specified encoding, and closes the file.
  794. /// </summary>
  795. /// <param name="path">The file to open for reading.</param>
  796. /// <param name="encoding">The encoding applied to the contents of the file.</param>
  797. /// <returns>
  798. /// A string containing all lines of the file.
  799. /// </returns>
  800. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  801. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  802. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  803. string ReadAllText(string path, Encoding encoding);
  804. /// <summary>
  805. /// Reads the lines of a file with the UTF-8 encoding.
  806. /// </summary>
  807. /// <param name="path">The file to read.</param>
  808. /// <returns>
  809. /// The lines of the file.
  810. /// </returns>
  811. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  812. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  813. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  814. IEnumerable<string> ReadLines(string path);
  815. /// <summary>
  816. /// Read the lines of a file that has a specified encoding.
  817. /// </summary>
  818. /// <param name="path">The file to read.</param>
  819. /// <param name="encoding">The encoding that is applied to the contents of the file.</param>
  820. /// <returns>
  821. /// The lines of the file.
  822. /// </returns>
  823. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  824. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  825. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  826. IEnumerable<string> ReadLines(string path, Encoding encoding);
  827. /// <summary>
  828. /// Renames remote file from old path to new path.
  829. /// </summary>
  830. /// <param name="oldPath">Path to the old file location.</param>
  831. /// <param name="newPath">Path to the new file location.</param>
  832. /// <exception cref="ArgumentNullException"><paramref name="oldPath"/> is <b>null</b>. <para>-or-</para> or <paramref name="newPath"/> is <b>null</b>.</exception>
  833. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  834. /// <exception cref="SftpPermissionDeniedException">Permission to rename the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  835. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message"/> is the message from the remote host.</exception>
  836. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  837. void RenameFile(string oldPath, string newPath);
  838. /// <summary>
  839. /// Asynchronously renames remote file from old path to new path.
  840. /// </summary>
  841. /// <param name="oldPath">Path to the old file location.</param>
  842. /// <param name="newPath">Path to the new file location.</param>
  843. /// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
  844. /// <returns>A <see cref="Task"/> that represents the asynchronous rename operation.</returns>
  845. /// <exception cref="ArgumentNullException"><paramref name="oldPath"/> is <b>null</b>. <para>-or-</para> or <paramref name="newPath"/> is <b>null</b>.</exception>
  846. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  847. /// <exception cref="SftpPermissionDeniedException">Permission to rename the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  848. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message"/> is the message from the remote host.</exception>
  849. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  850. Task RenameFileAsync(string oldPath, string newPath, CancellationToken cancellationToken);
  851. /// <summary>
  852. /// Renames remote file from old path to new path.
  853. /// </summary>
  854. /// <param name="oldPath">Path to the old file location.</param>
  855. /// <param name="newPath">Path to the new file location.</param>
  856. /// <param name="isPosix">if set to <c>true</c> then perform a posix rename.</param>
  857. /// <exception cref="ArgumentNullException"><paramref name="oldPath" /> is <b>null</b>. <para>-or-</para> or <paramref name="newPath" /> is <b>null</b>.</exception>
  858. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  859. /// <exception cref="SftpPermissionDeniedException">Permission to rename the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  860. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  861. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  862. void RenameFile(string oldPath, string newPath, bool isPosix);
  863. /// <summary>
  864. /// Sets the date and time the specified file was last accessed.
  865. /// </summary>
  866. /// <param name="path">The file for which to set the access date and time information.</param>
  867. /// <param name="lastAccessTime">A <see cref="DateTime"/> containing the value to set for the last access date and time of path. This value is expressed in local time.</param>
  868. void SetLastAccessTime(string path, DateTime lastAccessTime);
  869. /// <summary>
  870. /// Sets the date and time, in coordinated universal time (UTC), that the specified file was last accessed.
  871. /// </summary>
  872. /// <param name="path">The file for which to set the access date and time information.</param>
  873. /// <param name="lastAccessTimeUtc">A <see cref="DateTime"/> containing the value to set for the last access date and time of path. This value is expressed in UTC time.</param>
  874. void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc);
  875. /// <summary>
  876. /// Sets the date and time that the specified file was last written to.
  877. /// </summary>
  878. /// <param name="path">The file for which to set the date and time information.</param>
  879. /// <param name="lastWriteTime">A <see cref="DateTime"/> containing the value to set for the last write date and time of path. This value is expressed in local time.</param>
  880. void SetLastWriteTime(string path, DateTime lastWriteTime);
  881. /// <summary>
  882. /// Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.
  883. /// </summary>
  884. /// <param name="path">The file for which to set the date and time information.</param>
  885. /// <param name="lastWriteTimeUtc">A <see cref="DateTime"/> containing the value to set for the last write date and time of path. This value is expressed in UTC time.</param>
  886. void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc);
  887. /// <summary>
  888. /// Sets the specified <see cref="SftpFileAttributes"/> of the file on the specified path.
  889. /// </summary>
  890. /// <param name="path">The path to the file.</param>
  891. /// <param name="fileAttributes">The desired <see cref="SftpFileAttributes"/>.</param>
  892. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  893. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  894. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  895. void SetAttributes(string path, SftpFileAttributes fileAttributes);
  896. /// <summary>
  897. /// Creates a symbolic link from old path to new path.
  898. /// </summary>
  899. /// <param name="path">The old path.</param>
  900. /// <param name="linkPath">The new path.</param>
  901. /// <exception cref="ArgumentException"><paramref name="path"/> is <b>null</b>. <para>-or-</para> <paramref name="linkPath"/> is <b>null</b> or contains only whitespace characters.</exception>
  902. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  903. /// <exception cref="SftpPermissionDeniedException">Permission to create the symbolic link was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  904. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message"/> is the message from the remote host.</exception>
  905. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  906. void SymbolicLink(string path, string linkPath);
  907. /// <summary>
  908. /// Synchronizes the directories.
  909. /// </summary>
  910. /// <param name="sourcePath">The source path.</param>
  911. /// <param name="destinationPath">The destination path.</param>
  912. /// <param name="searchPattern">The search pattern.</param>
  913. /// <returns>
  914. /// A list of uploaded files.
  915. /// </returns>
  916. /// <exception cref="ArgumentNullException"><paramref name="sourcePath"/> is <c>null</c>.</exception>
  917. /// <exception cref="ArgumentException"><paramref name="destinationPath"/> is <c>null</c> or contains only whitespace.</exception>
  918. /// <exception cref="SftpPathNotFoundException"><paramref name="destinationPath"/> was not found on the remote host.</exception>
  919. /// <exception cref="SshException">If a problem occurs while copying the file</exception>
  920. IEnumerable<FileInfo> SynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern);
  921. /// <summary>
  922. /// Uploads stream into remote file.
  923. /// </summary>
  924. /// <param name="input">Data input stream.</param>
  925. /// <param name="path">Remote file path.</param>
  926. /// <param name="uploadCallback">The upload callback.</param>
  927. /// <exception cref="ArgumentNullException"><paramref name="input" /> is <b>null</b>.</exception>
  928. /// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains only whitespace characters.</exception>
  929. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  930. /// <exception cref="SftpPermissionDeniedException">Permission to upload the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  931. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  932. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  933. /// <remarks>
  934. /// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
  935. /// </remarks>
  936. void UploadFile(Stream input, string path, Action<ulong> uploadCallback = null);
  937. /// <summary>
  938. /// Uploads stream into remote file.
  939. /// </summary>
  940. /// <param name="input">Data input stream.</param>
  941. /// <param name="path">Remote file path.</param>
  942. /// <param name="canOverride">if set to <c>true</c> then existing file will be overwritten.</param>
  943. /// <param name="uploadCallback">The upload callback.</param>
  944. /// <exception cref="ArgumentNullException"><paramref name="input" /> is <b>null</b>.</exception>
  945. /// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains only whitespace characters.</exception>
  946. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  947. /// <exception cref="SftpPermissionDeniedException">Permission to upload the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
  948. /// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
  949. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  950. /// <remarks>
  951. /// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
  952. /// </remarks>
  953. void UploadFile(Stream input, string path, bool canOverride, Action<ulong> uploadCallback = null);
  954. /// <summary>
  955. /// Writes the specified byte array to the specified file, and closes the file.
  956. /// </summary>
  957. /// <param name="path">The file to write to.</param>
  958. /// <param name="bytes">The bytes to write to the file.</param>
  959. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  960. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  961. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  962. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  963. /// <remarks>
  964. /// <para>
  965. /// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
  966. /// </para>
  967. /// <para>
  968. /// If the target file does not exist, it is created.
  969. /// </para>
  970. /// </remarks>
  971. void WriteAllBytes(string path, byte[] bytes);
  972. /// <summary>
  973. /// Writes a collection of strings to the file using the UTF-8 encoding, and closes the file.
  974. /// </summary>
  975. /// <param name="path">The file to write to.</param>
  976. /// <param name="contents">The lines to write to the file.</param>
  977. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  978. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  979. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  980. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  981. /// <remarks>
  982. /// <para>
  983. /// The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
  984. /// </para>
  985. /// <para>
  986. /// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
  987. /// </para>
  988. /// <para>
  989. /// If the target file does not exist, it is created.
  990. /// </para>
  991. /// </remarks>
  992. void WriteAllLines(string path, IEnumerable<string> contents);
  993. /// <summary>
  994. /// Writes a collection of strings to the file using the specified encoding, and closes the file.
  995. /// </summary>
  996. /// <param name="path">The file to write to.</param>
  997. /// <param name="contents">The lines to write to the file.</param>
  998. /// <param name="encoding">The character encoding to use.</param>
  999. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  1000. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  1001. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  1002. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  1003. /// <remarks>
  1004. /// <para>
  1005. /// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
  1006. /// </para>
  1007. /// <para>
  1008. /// If the target file does not exist, it is created.
  1009. /// </para>
  1010. /// </remarks>
  1011. void WriteAllLines(string path, IEnumerable<string> contents, Encoding encoding);
  1012. /// <summary>
  1013. /// Write the specified string array to the file using the UTF-8 encoding, and closes the file.
  1014. /// </summary>
  1015. /// <param name="path">The file to write to.</param>
  1016. /// <param name="contents">The string array to write to the file.</param>
  1017. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  1018. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  1019. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  1020. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  1021. /// <remarks>
  1022. /// <para>
  1023. /// The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
  1024. /// </para>
  1025. /// <para>
  1026. /// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
  1027. /// </para>
  1028. /// <para>
  1029. /// If the target file does not exist, it is created.
  1030. /// </para>
  1031. /// </remarks>
  1032. void WriteAllLines(string path, string[] contents);
  1033. /// <summary>
  1034. /// Writes the specified string array to the file by using the specified encoding, and closes the file.
  1035. /// </summary>
  1036. /// <param name="path">The file to write to.</param>
  1037. /// <param name="contents">The string array to write to the file.</param>
  1038. /// <param name="encoding">An <see cref="Encoding"/> object that represents the character encoding applied to the string array.</param>
  1039. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  1040. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  1041. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  1042. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  1043. /// <remarks>
  1044. /// <para>
  1045. /// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
  1046. /// </para>
  1047. /// <para>
  1048. /// If the target file does not exist, it is created.
  1049. /// </para>
  1050. /// </remarks>
  1051. void WriteAllLines(string path, string[] contents, Encoding encoding);
  1052. /// <summary>
  1053. /// Writes the specified string to the file using the UTF-8 encoding, and closes the file.
  1054. /// </summary>
  1055. /// <param name="path">The file to write to.</param>
  1056. /// <param name="contents">The string to write to the file.</param>
  1057. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  1058. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  1059. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  1060. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  1061. /// <remarks>
  1062. /// <para>
  1063. /// The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
  1064. /// </para>
  1065. /// <para>
  1066. /// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
  1067. /// </para>
  1068. /// <para>
  1069. /// If the target file does not exist, it is created.
  1070. /// </para>
  1071. /// </remarks>
  1072. void WriteAllText(string path, string contents);
  1073. /// <summary>
  1074. /// Writes the specified string to the file using the specified encoding, and closes the file.
  1075. /// </summary>
  1076. /// <param name="path">The file to write to.</param>
  1077. /// <param name="contents">The string to write to the file.</param>
  1078. /// <param name="encoding">The encoding to apply to the string.</param>
  1079. /// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
  1080. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  1081. /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
  1082. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  1083. /// <remarks>
  1084. /// <para>
  1085. /// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
  1086. /// </para>
  1087. /// <para>
  1088. /// If the target file does not exist, it is created.
  1089. /// </para>
  1090. /// </remarks>
  1091. void WriteAllText(string path, string contents, Encoding encoding);
  1092. }
  1093. }