Interface ISftpClient
- Namespace
- Renci.SshNet
- Assembly
- Renci.SshNet.dll
Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
public interface ISftpClient : IBaseClient, IDisposable
Implements
Properties
BufferSize
Gets or sets the maximum size of the buffer in bytes.
uint BufferSize { get; set; }
Property Value
Remarks
For write operations, this limits the size of the payload for individual SSH_FXP_WRITE messages. The actual size is always capped at the maximum packet size supported by the peer (minus the size of protocol fields).
For read operations, this controls the size of the payload which is requested from the peer in a SSH_FXP_READ message. The peer will send the requested number of bytes in a SSH_FXP_DATA message, possibly split over multiple SSH_MSG_CHANNEL_DATA messages.
To optimize the size of the SSH packets sent by the peer, the actual requested size will take into account the size of the SSH_FXP_DATA protocol fields.
The size of the each individual SSH_FXP_DATA message is limited to the
local maximum packet size of the channel, which is set to 64 KB
for SSH.NET. However, the peer can limit this even further.
Exceptions
- ObjectDisposedException
-
The method was called after the client was disposed.
OperationTimeout
Gets or sets the operation timeout.
TimeSpan OperationTimeout { get; set; }
Property Value
Exceptions
- ArgumentOutOfRangeException
-
value
represents a value that is less than -1 or greater than System.Int32.MaxValue milliseconds.
ProtocolVersion
Gets sftp protocol version.
int ProtocolVersion { get; }
Property Value
Exceptions
- SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
WorkingDirectory
Gets remote working directory.
string WorkingDirectory { get; }
Property Value
Exceptions
- SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
Methods
AppendAllLines(string, IEnumerable<string>)
Appends lines to a file, creating the file if it does not already exist.
void AppendAllLines(string path, IEnumerable<string> contents)
Parameters
path
string-
The file to append the lines to. The file is created if it does not already exist.
contents
IEnumerable<string>-
The lines to append to the file.
Remarks
The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
Exceptions
- ArgumentNullException
-
path
is null.-or-
contents
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
AppendAllLines(string, IEnumerable<string>, Encoding)
Appends lines to a file by using a specified encoding, creating the file if it does not already exist.
void AppendAllLines(string path, IEnumerable<string> contents, Encoding encoding)
Parameters
path
string-
The file to append the lines to. The file is created if it does not already exist.
contents
IEnumerable<string>-
The lines to append to the file.
encoding
Encoding-
The character encoding to use.
Exceptions
- ArgumentNullException
-
path
is null.-or-
contents
is null.-or-
encoding
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
AppendAllText(string, string)
Appends the specified string to the file, creating the file if it does not already exist.
void AppendAllText(string path, string contents)
Parameters
path
string-
The file to append the specified string to.
contents
string-
The string to append to the file.
Remarks
The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
Exceptions
- ArgumentNullException
-
path
is null.-or-
contents
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
AppendAllText(string, string, Encoding)
Appends the specified string to the file, creating the file if it does not already exist.
void AppendAllText(string path, string contents, Encoding encoding)
Parameters
path
string-
The file to append the specified string to.
contents
string-
The string to append to the file.
encoding
Encoding-
The character encoding to use.
Exceptions
- ArgumentNullException
-
path
is null.-or-
contents
is null.-or-
encoding
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
AppendText(string)
Creates a System.IO.StreamWriter that appends UTF-8 encoded text to the specified file, creating the file if it does not already exist.
StreamWriter AppendText(string path)
Parameters
path
string-
The path to the file to append to.
Returns
- StreamWriter
-
A System.IO.StreamWriter that appends text to a file using UTF-8 encoding without a Byte-Order Mark (BOM).
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
AppendText(string, Encoding)
Creates a System.IO.StreamWriter that appends text to a file using the specified encoding, creating the file if it does not already exist.
StreamWriter AppendText(string path, Encoding encoding)
Parameters
Returns
- StreamWriter
-
A System.IO.StreamWriter that appends text to a file using the specified encoding.
Exceptions
- ArgumentNullException
-
path
is null.-or-
encoding
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
BeginDownloadFile(string, Stream)
Begins an asynchronous file downloading into the stream.
IAsyncResult BeginDownloadFile(string path, Stream output)
Parameters
Returns
- IAsyncResult
-
An System.IAsyncResult that references the asynchronous operation.
Remarks
Method calls made by this method to output
, may under certain conditions result in exceptions thrown by the stream.
Exceptions
- ArgumentNullException
-
output
is null. - ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to perform the operation was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
BeginDownloadFile(string, Stream, AsyncCallback?)
Begins an asynchronous file downloading into the stream.
IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback? asyncCallback)
Parameters
path
string-
The path.
output
Stream-
The output.
asyncCallback
AsyncCallback?-
The method to be called when the asynchronous write operation is completed.
Returns
- IAsyncResult
-
An System.IAsyncResult that references the asynchronous operation.
Remarks
Method calls made by this method to output
, may under certain conditions result in exceptions thrown by the stream.
Exceptions
- ArgumentNullException
-
output
is null. - ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to perform the operation was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
BeginDownloadFile(string, Stream, AsyncCallback?, object?, Action<ulong>?)
Begins an asynchronous file downloading into the stream.
IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback? asyncCallback, object? state, Action<ulong>? downloadCallback = null)
Parameters
path
string-
The path.
output
Stream-
The output.
asyncCallback
AsyncCallback?-
The method to be called when the asynchronous write operation is completed.
state
object?-
A user-provided object that distinguishes this particular asynchronous write request from other requests.
downloadCallback
Action<ulong>?-
The download callback.
Returns
- IAsyncResult
-
An System.IAsyncResult that references the asynchronous operation.
Remarks
Method calls made by this method to output
, may under certain conditions result in exceptions thrown by the stream.
Exceptions
- ArgumentNullException
-
output
is null. - ArgumentException
-
path
is null or contains only whitespace characters. - ObjectDisposedException
-
The method was called after the client was disposed.
BeginListDirectory(string, AsyncCallback?, object?, Action<int>?)
Begins an asynchronous operation of retrieving list of files in remote directory.
IAsyncResult BeginListDirectory(string path, AsyncCallback? asyncCallback, object? state, Action<int>? listCallback = null)
Parameters
path
string-
The path.
asyncCallback
AsyncCallback?-
The method to be called when the asynchronous write operation is completed.
state
object?-
A user-provided object that distinguishes this particular asynchronous write request from other requests.
listCallback
Action<int>?-
The list callback.
Returns
- IAsyncResult
-
An System.IAsyncResult that references the asynchronous operation.
Exceptions
- ObjectDisposedException
-
The method was called after the client was disposed.
BeginSynchronizeDirectories(string, string, string, AsyncCallback?, object?)
Begins the synchronize directories.
IAsyncResult BeginSynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern, AsyncCallback? asyncCallback, object? state)
Parameters
sourcePath
string-
The source path.
destinationPath
string-
The destination path.
searchPattern
string-
The search pattern.
asyncCallback
AsyncCallback?-
The async callback.
state
object?-
The state.
Returns
- IAsyncResult
-
An System.IAsyncResult that represents the asynchronous directory synchronization.
Exceptions
- ArgumentNullException
-
sourcePath
is null. - ArgumentException
-
destinationPath
is null or contains only whitespace. - SshException
-
If a problem occurs while copying the file.
BeginUploadFile(Stream, string)
Begins an asynchronous uploading the stream into remote file.
IAsyncResult BeginUploadFile(Stream input, string path)
Parameters
Returns
- IAsyncResult
-
An System.IAsyncResult that references the asynchronous operation.
Remarks
Method calls made by this method to input
, may under certain conditions result in exceptions thrown by the stream.
If the remote file already exists, it is overwritten and truncated.
Exceptions
- ArgumentNullException
-
input
is null. - ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to list the contents of the directory was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
BeginUploadFile(Stream, string, AsyncCallback?)
Begins an asynchronous uploading the stream into remote file.
IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback? asyncCallback)
Parameters
input
Stream-
Data input stream.
path
string-
Remote file path.
asyncCallback
AsyncCallback?-
The method to be called when the asynchronous write operation is completed.
Returns
- IAsyncResult
-
An System.IAsyncResult that references the asynchronous operation.
Remarks
Method calls made by this method to input
, may under certain conditions result in exceptions thrown by the stream.
If the remote file already exists, it is overwritten and truncated.
Exceptions
- ArgumentNullException
-
input
is null. - ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to list the contents of the directory was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
BeginUploadFile(Stream, string, AsyncCallback?, object?, Action<ulong>?)
Begins an asynchronous uploading the stream into remote file.
IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback? asyncCallback, object? state, Action<ulong>? uploadCallback = null)
Parameters
input
Stream-
Data input stream.
path
string-
Remote file path.
asyncCallback
AsyncCallback?-
The method to be called when the asynchronous write operation is completed.
state
object?-
A user-provided object that distinguishes this particular asynchronous write request from other requests.
uploadCallback
Action<ulong>?-
The upload callback.
Returns
- IAsyncResult
-
An System.IAsyncResult that references the asynchronous operation.
Remarks
Method calls made by this method to input
, may under certain conditions result in exceptions thrown by the stream.
If the remote file already exists, it is overwritten and truncated.
Exceptions
- ArgumentNullException
-
input
is null. - ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to list the contents of the directory was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
BeginUploadFile(Stream, string, bool, AsyncCallback?, object?, Action<ulong>?)
Begins an asynchronous uploading the stream into remote file.
IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride, AsyncCallback? asyncCallback, object? state, Action<ulong>? uploadCallback = null)
Parameters
input
Stream-
Data input stream.
path
string-
Remote file path.
canOverride
bool-
Specified whether an existing file can be overwritten.
asyncCallback
AsyncCallback?-
The method to be called when the asynchronous write operation is completed.
state
object?-
A user-provided object that distinguishes this particular asynchronous write request from other requests.
uploadCallback
Action<ulong>?-
The upload callback.
Returns
- IAsyncResult
-
An System.IAsyncResult that references the asynchronous operation.
Remarks
Method calls made by this method to input
, may under certain conditions result in exceptions thrown by the stream.
When path
refers to an existing file, set canOverride
to true to overwrite and truncate that file.
If canOverride
is false, the upload will fail and Renci.SshNet.SftpClient.EndUploadFile(System.IAsyncResult) will throw an
Renci.SshNet.Common.SshException.
Exceptions
- ArgumentNullException
-
input
is null. - ArgumentException
-
path
is null or contains only whitespace characters. - ObjectDisposedException
-
The method was called after the client was disposed.
ChangeDirectory(string)
Changes remote directory to path.
void ChangeDirectory(string path)
Parameters
path
string-
New directory path.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to change directory denied by remote host.
-or-
A SSH command was denied by the server. - SftpPathNotFoundException
-
path
was not found on the remote host. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
ChangeDirectoryAsync(string, CancellationToken)
Asynchronously requests to change the current working directory to the specified path.
Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken = default)
Parameters
path
string-
The new working directory.
cancellationToken
CancellationToken-
The token to monitor for cancellation requests.
Returns
- Task
-
A System.Threading.Tasks.Task that tracks the asynchronous change working directory request.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to change directory denied by remote host.
-or-
A SSH command was denied by the server. - SftpPathNotFoundException
-
path
was not found on the remote host. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
ChangePermissions(string, short)
Changes permissions of file(s) to specified mode.
void ChangePermissions(string path, short mode)
Parameters
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to change permission on the path(s) was denied by the remote host.
-or-
A SSH command was denied by the server. - SftpPathNotFoundException
-
path
was not found on the remote host. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
Create(string)
Creates or overwrites a file in the specified path.
SftpFileStream Create(string path)
Parameters
path
string-
The path and name of the file to create.
Returns
- SftpFileStream
-
A Renci.SshNet.Sftp.SftpFileStream that provides read/write access to the file specified in path.
Remarks
If the target file already exists, it is first truncated to zero bytes.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
Create(string, int)
Creates or overwrites the specified file.
SftpFileStream Create(string path, int bufferSize)
Parameters
path
string-
The path and name of the file to create.
bufferSize
int-
The maximum number of bytes buffered for reads and writes to the file.
Returns
- SftpFileStream
-
A Renci.SshNet.Sftp.SftpFileStream that provides read/write access to the file specified in path.
Remarks
If the target file already exists, it is first truncated to zero bytes.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
CreateDirectory(string)
Creates remote directory specified by path.
void CreateDirectory(string path)
Parameters
path
string-
Directory path to create.
Exceptions
- ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to create the directory was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
CreateDirectoryAsync(string, CancellationToken)
Asynchronously requests to create a remote directory specified by path.
Task CreateDirectoryAsync(string path, CancellationToken cancellationToken = default)
Parameters
path
string-
Directory path to create.
cancellationToken
CancellationToken-
The System.Threading.CancellationToken to observe.
Returns
- Task
-
A System.Threading.Tasks.Task that represents the asynchronous create directory operation.
Exceptions
- ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to create the directory was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
CreateText(string)
Creates or opens a file for writing UTF-8 encoded text.
StreamWriter CreateText(string path)
Parameters
path
string-
The file to be opened for writing.
Returns
- StreamWriter
-
A System.IO.StreamWriter that writes text to a file using UTF-8 encoding without a Byte-Order Mark (BOM).
Remarks
If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
If the target file does not exist, it is created.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
CreateText(string, Encoding)
Creates or opens a file for writing text using the specified encoding.
StreamWriter CreateText(string path, Encoding encoding)
Parameters
Returns
- StreamWriter
-
A System.IO.StreamWriter that writes to a file using the specified encoding.
Remarks
If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
If the target file does not exist, it is created.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
Delete(string)
Deletes the specified file or directory.
void Delete(string path)
Parameters
path
string-
The name of the file or directory to be deleted. Wildcard characters are not supported.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
path
was not found on the remote host. - ObjectDisposedException
-
The method was called after the client was disposed.
DeleteAsync(string, CancellationToken)
Permanently deletes a file on remote machine.
Task DeleteAsync(string path, CancellationToken cancellationToken = default)
Parameters
path
string-
The name of the file or directory to be deleted. Wildcard characters are not supported.
cancellationToken
CancellationToken-
The System.Threading.CancellationToken to observe.
Returns
- Task
-
A System.Threading.Tasks.Task that represents the asynchronous delete operation.
DeleteDirectory(string)
Deletes remote directory specified by path.
void DeleteDirectory(string path)
Parameters
path
string-
Directory to be deleted path.
Exceptions
- ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
path
was not found on the remote host. - SftpPermissionDeniedException
-
Permission to delete the directory was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
DeleteDirectoryAsync(string, CancellationToken)
Asynchronously deletes a remote directory.
Task DeleteDirectoryAsync(string path, CancellationToken cancellationToken = default)
Parameters
path
string-
The path of the directory to be deleted.
cancellationToken
CancellationToken-
The System.Threading.CancellationToken to observe.
Returns
- Task
-
A System.Threading.Tasks.Task that represents the asynchronous delete operation.
Exceptions
- ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
path
was not found on the remote host. - SftpPermissionDeniedException
-
Permission to delete the directory was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
DeleteFile(string)
Deletes remote file specified by path.
void DeleteFile(string path)
Parameters
path
string-
File to be deleted path.
Exceptions
- ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
path
was not found on the remote host. - SftpPermissionDeniedException
-
Permission to delete the file was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
DeleteFileAsync(string, CancellationToken)
Asynchronously deletes remote file specified by path.
Task DeleteFileAsync(string path, CancellationToken cancellationToken)
Parameters
path
string-
File to be deleted path.
cancellationToken
CancellationToken-
The System.Threading.CancellationToken to observe.
Returns
- Task
-
A System.Threading.Tasks.Task that represents the asynchronous delete operation.
Exceptions
- ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
path
was not found on the remote host. - SftpPermissionDeniedException
-
Permission to delete the file was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
DownloadFile(string, Stream, Action<ulong>?)
Downloads remote file specified by the path into the stream.
void DownloadFile(string path, Stream output, Action<ulong>? downloadCallback = null)
Parameters
path
string-
File to download.
output
Stream-
Stream to write the file into.
downloadCallback
Action<ulong>?-
The download callback.
Remarks
Method calls made by this method to output
, may under certain conditions result in exceptions thrown by the stream.
Exceptions
- ArgumentNullException
-
output
is null. - ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to perform the operation was denied by the remote host.
-or-
A SSH command was denied by the server. - SftpPathNotFoundException
-
path
was not found on the remote host. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
EndDownloadFile(IAsyncResult)
Ends an asynchronous file downloading into the stream.
void EndDownloadFile(IAsyncResult asyncResult)
Parameters
asyncResult
IAsyncResult-
The pending asynchronous SFTP request.
Exceptions
- ArgumentException
-
The System.IAsyncResult object did not come from the corresponding async method on this type.
-or-
Renci.SshNet.SftpClient.EndDownloadFile(System.IAsyncResult) was called multiple times with the same System.IAsyncResult. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to perform the operation was denied by the remote host.
-or-
A SSH command was denied by the server. - SftpPathNotFoundException
-
The path was not found on the remote host.
- SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
EndListDirectory(IAsyncResult)
Ends an asynchronous operation of retrieving list of files in remote directory.
IEnumerable<ISftpFile> EndListDirectory(IAsyncResult asyncResult)
Parameters
asyncResult
IAsyncResult-
The pending asynchronous SFTP request.
Returns
- IEnumerable<ISftpFile>
-
A list of files.
Exceptions
- ArgumentException
-
The System.IAsyncResult object did not come from the corresponding async method on this type.
-or-
Renci.SshNet.SftpClient.EndListDirectory(System.IAsyncResult) was called multiple times with the same System.IAsyncResult.
EndSynchronizeDirectories(IAsyncResult)
Ends the synchronize directories.
IEnumerable<FileInfo> EndSynchronizeDirectories(IAsyncResult asyncResult)
Parameters
asyncResult
IAsyncResult-
The async result.
Returns
- IEnumerable<FileInfo>
-
A list of uploaded files.
Exceptions
- ArgumentException
-
The System.IAsyncResult object did not come from the corresponding async method on this type.
-or-
Renci.SshNet.SftpClient.EndSynchronizeDirectories(System.IAsyncResult) was called multiple times with the same System.IAsyncResult. - SftpPathNotFoundException
-
The destination path was not found on the remote host.
EndUploadFile(IAsyncResult)
Ends an asynchronous uploading the stream into remote file.
void EndUploadFile(IAsyncResult asyncResult)
Parameters
asyncResult
IAsyncResult-
The pending asynchronous SFTP request.
Exceptions
- ArgumentException
-
The System.IAsyncResult object did not come from the corresponding async method on this type.
-or-
Renci.SshNet.SftpClient.EndUploadFile(System.IAsyncResult) was called multiple times with the same System.IAsyncResult. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The directory of the file was not found on the remote host.
- SftpPermissionDeniedException
-
Permission to upload the file was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
Exists(string)
Checks whether file or directory exists.
bool Exists(string path)
Parameters
path
string-
The path.
Returns
Exceptions
- ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to perform the operation was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
Get(string)
Gets reference to remote file or directory.
ISftpFile Get(string path)
Parameters
path
string-
The path.
Returns
- ISftpFile
-
A reference to Renci.SshNet.Sftp.ISftpFile file object.
Exceptions
- SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
path
was not found on the remote host. - ArgumentNullException
-
path
is null. - ObjectDisposedException
-
The method was called after the client was disposed.
GetAttributes(string)
Gets the Renci.SshNet.Sftp.SftpFileAttributes of the file on the path.
SftpFileAttributes GetAttributes(string path)
Parameters
path
string-
The path to the file.
Returns
- SftpFileAttributes
-
The Renci.SshNet.Sftp.SftpFileAttributes of the file on the path.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
path
was not found on the remote host. - ObjectDisposedException
-
The method was called after the client was disposed.
GetLastAccessTime(string)
Returns the date and time the specified file or directory was last accessed.
DateTime GetLastAccessTime(string path)
Parameters
path
string-
The file or directory for which to obtain access date and time information.
Returns
- DateTime
-
A System.DateTime structure set to the date and time that the specified file or directory was last accessed. This value is expressed in local time.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
GetLastAccessTimeUtc(string)
Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last accessed.
DateTime GetLastAccessTimeUtc(string path)
Parameters
path
string-
The file or directory for which to obtain access date and time information.
Returns
- DateTime
-
A System.DateTime structure set to the date and time that the specified file or directory was last accessed. This value is expressed in UTC time.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
GetLastWriteTime(string)
Returns the date and time the specified file or directory was last written to.
DateTime GetLastWriteTime(string path)
Parameters
path
string-
The file or directory for which to obtain write date and time information.
Returns
- DateTime
-
A System.DateTime structure set to the date and time that the specified file or directory was last written to. This value is expressed in local time.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
GetLastWriteTimeUtc(string)
Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last written to.
DateTime GetLastWriteTimeUtc(string path)
Parameters
path
string-
The file or directory for which to obtain write date and time information.
Returns
- DateTime
-
A System.DateTime structure set to the date and time that the specified file or directory was last written to. This value is expressed in UTC time.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
GetStatus(string)
Gets status using statvfs@openssh.com request.
SftpFileSystemInformation GetStatus(string path)
Parameters
path
string-
The path.
Returns
- SftpFileSystemInformation
-
A Renci.SshNet.Sftp.SftpFileSystemInformation instance that contains file status information.
Exceptions
- SshConnectionException
-
Client is not connected.
- ArgumentNullException
-
path
is null. - ObjectDisposedException
-
The method was called after the client was disposed.
GetStatusAsync(string, CancellationToken)
Asynchronously gets status using statvfs@openssh.com request.
Task<SftpFileSystemInformation> GetStatusAsync(string path, CancellationToken cancellationToken)
Parameters
path
string-
The path.
cancellationToken
CancellationToken-
The System.Threading.CancellationToken to observe.
Returns
- Task<SftpFileSystemInformation>
-
A System.Threading.Tasks.Task`1 that represents the status operation. The task result contains the Renci.SshNet.Sftp.SftpFileSystemInformation instance that contains file status information.
Exceptions
- SshConnectionException
-
Client is not connected.
- ArgumentNullException
-
path
is null. - ObjectDisposedException
-
The method was called after the client was disposed.
ListDirectory(string, Action<int>?)
Retrieves list of files in remote directory.
IEnumerable<ISftpFile> ListDirectory(string path, Action<int>? listCallback = null)
Parameters
Returns
- IEnumerable<ISftpFile>
-
A list of files.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to list the contents of the directory was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
ListDirectoryAsync(string, CancellationToken)
Asynchronously enumerates the files in remote directory.
IAsyncEnumerable<ISftpFile> ListDirectoryAsync(string path, CancellationToken cancellationToken)
Parameters
path
string-
The path.
cancellationToken
CancellationToken-
The System.Threading.CancellationToken to observe.
Returns
- IAsyncEnumerable<ISftpFile>
-
An System.Collections.Generic.IAsyncEnumerable`1 of Renci.SshNet.Sftp.ISftpFile that represents the asynchronous enumeration operation. The enumeration contains an async stream of Renci.SshNet.Sftp.ISftpFile for the files in the directory specified by
path
.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to list the contents of the directory was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
Open(string, FileMode)
Opens a Renci.SshNet.Sftp.SftpFileStream on the specified path with read/write access.
SftpFileStream Open(string path, FileMode mode)
Parameters
path
string-
The file to open.
mode
FileMode-
A System.IO.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.
Returns
- SftpFileStream
-
An unshared Renci.SshNet.Sftp.SftpFileStream that provides access to the specified file, with the specified mode and read/write access.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
Open(string, FileMode, FileAccess)
Opens a Renci.SshNet.Sftp.SftpFileStream on the specified path, with the specified mode and access.
SftpFileStream Open(string path, FileMode mode, FileAccess access)
Parameters
path
string-
The file to open.
mode
FileMode-
A System.IO.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.
access
FileAccess-
A System.IO.FileAccess value that specifies the operations that can be performed on the file.
Returns
- SftpFileStream
-
An unshared Renci.SshNet.Sftp.SftpFileStream that provides access to the specified file, with the specified mode and access.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
OpenAsync(string, FileMode, FileAccess, CancellationToken)
Asynchronously opens a Renci.SshNet.Sftp.SftpFileStream on the specified path, with the specified mode and access.
Task<SftpFileStream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken)
Parameters
path
string-
The file to open.
mode
FileMode-
A System.IO.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.
access
FileAccess-
A System.IO.FileAccess value that specifies the operations that can be performed on the file.
cancellationToken
CancellationToken-
The System.Threading.CancellationToken to observe.
Returns
- Task<SftpFileStream>
-
A System.Threading.Tasks.Task`1 that represents the asynchronous open operation. The task result contains the Renci.SshNet.Sftp.SftpFileStream that provides access to the specified file, with the specified mode and access.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
OpenRead(string)
Opens an existing file for reading.
SftpFileStream OpenRead(string path)
Parameters
path
string-
The file to be opened for reading.
Returns
- SftpFileStream
-
A read-only Renci.SshNet.Sftp.SftpFileStream on the specified path.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
OpenText(string)
Opens an existing UTF-8 encoded text file for reading.
StreamReader OpenText(string path)
Parameters
path
string-
The file to be opened for reading.
Returns
- StreamReader
-
A System.IO.StreamReader on the specified path.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
OpenWrite(string)
Opens a file for writing.
SftpFileStream OpenWrite(string path)
Parameters
path
string-
The file to be opened for writing.
Returns
- SftpFileStream
-
An unshared Renci.SshNet.Sftp.SftpFileStream object on the specified path with System.IO.FileAccess.Write access.
Remarks
If the file does not exist, it is created.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
ReadAllBytes(string)
Opens a binary file, reads the contents of the file into a byte array, and closes the file.
byte[] ReadAllBytes(string path)
Parameters
path
string-
The file to open for reading.
Returns
- byte[]
-
A byte array containing the contents of the file.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
ReadAllLines(string)
Opens a text file, reads all lines of the file using UTF-8 encoding, and closes the file.
string[] ReadAllLines(string path)
Parameters
path
string-
The file to open for reading.
Returns
- string[]
-
A string array containing all lines of the file.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
ReadAllLines(string, Encoding)
Opens a file, reads all lines of the file with the specified encoding, and closes the file.
string[] ReadAllLines(string path, Encoding encoding)
Parameters
path
string-
The file to open for reading.
encoding
Encoding-
The encoding applied to the contents of the file.
Returns
- string[]
-
A string array containing all lines of the file.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
ReadAllText(string)
Opens a text file, reads all lines of the file with the UTF-8 encoding, and closes the file.
string ReadAllText(string path)
Parameters
path
string-
The file to open for reading.
Returns
- string
-
A string containing all lines of the file.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
ReadAllText(string, Encoding)
Opens a file, reads all lines of the file with the specified encoding, and closes the file.
string ReadAllText(string path, Encoding encoding)
Parameters
path
string-
The file to open for reading.
encoding
Encoding-
The encoding applied to the contents of the file.
Returns
- string
-
A string containing all lines of the file.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
ReadLines(string)
Reads the lines of a file with the UTF-8 encoding.
IEnumerable<string> ReadLines(string path)
Parameters
path
string-
The file to read.
Returns
- IEnumerable<string>
-
The lines of the file.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
ReadLines(string, Encoding)
Read the lines of a file that has a specified encoding.
IEnumerable<string> ReadLines(string path, Encoding encoding)
Parameters
path
string-
The file to read.
encoding
Encoding-
The encoding that is applied to the contents of the file.
Returns
- IEnumerable<string>
-
The lines of the file.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
RenameFile(string, string)
Renames remote file from old path to new path.
void RenameFile(string oldPath, string newPath)
Parameters
Exceptions
- ArgumentNullException
-
oldPath
is null.-or-
ornewPath
is null. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to rename the file was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
RenameFile(string, string, bool)
Renames remote file from old path to new path.
void RenameFile(string oldPath, string newPath, bool isPosix)
Parameters
oldPath
string-
Path to the old file location.
newPath
string-
Path to the new file location.
isPosix
bool-
if set to true then perform a posix rename.
Exceptions
- ArgumentNullException
-
oldPath
is null.-or-
ornewPath
is null. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to rename the file was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
RenameFileAsync(string, string, CancellationToken)
Asynchronously renames remote file from old path to new path.
Task RenameFileAsync(string oldPath, string newPath, CancellationToken cancellationToken)
Parameters
oldPath
string-
Path to the old file location.
newPath
string-
Path to the new file location.
cancellationToken
CancellationToken-
The System.Threading.CancellationToken to observe.
Returns
- Task
-
A System.Threading.Tasks.Task that represents the asynchronous rename operation.
Exceptions
- ArgumentNullException
-
oldPath
is null.-or-
ornewPath
is null. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to rename the file was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
SetAttributes(string, SftpFileAttributes)
Sets the specified Renci.SshNet.Sftp.SftpFileAttributes of the file on the specified path.
void SetAttributes(string path, SftpFileAttributes fileAttributes)
Parameters
path
string-
The path to the file.
fileAttributes
SftpFileAttributes-
The desired Renci.SshNet.Sftp.SftpFileAttributes.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- ObjectDisposedException
-
The method was called after the client was disposed.
SetLastAccessTime(string, DateTime)
Sets the date and time the specified file was last accessed.
void SetLastAccessTime(string path, DateTime lastAccessTime)
Parameters
path
string-
The file for which to set the access date and time information.
lastAccessTime
DateTime-
A System.DateTime containing the value to set for the last access date and time of path. This value is expressed in local time.
SetLastAccessTimeUtc(string, DateTime)
Sets the date and time, in coordinated universal time (UTC), that the specified file was last accessed.
void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)
Parameters
path
string-
The file for which to set the access date and time information.
lastAccessTimeUtc
DateTime-
A System.DateTime containing the value to set for the last access date and time of path. This value is expressed in UTC time.
SetLastWriteTime(string, DateTime)
Sets the date and time that the specified file was last written to.
void SetLastWriteTime(string path, DateTime lastWriteTime)
Parameters
path
string-
The file for which to set the date and time information.
lastWriteTime
DateTime-
A System.DateTime containing the value to set for the last write date and time of path. This value is expressed in local time.
SetLastWriteTimeUtc(string, DateTime)
Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.
void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
Parameters
path
string-
The file for which to set the date and time information.
lastWriteTimeUtc
DateTime-
A System.DateTime containing the value to set for the last write date and time of path. This value is expressed in UTC time.
SymbolicLink(string, string)
Creates a symbolic link from old path to new path.
void SymbolicLink(string path, string linkPath)
Parameters
Exceptions
- ArgumentException
-
path
is null.-or-
linkPath
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to create the symbolic link was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
SynchronizeDirectories(string, string, string)
Synchronizes the directories.
IEnumerable<FileInfo> SynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern)
Parameters
sourcePath
string-
The source path.
destinationPath
string-
The destination path.
searchPattern
string-
The search pattern.
Returns
- IEnumerable<FileInfo>
-
A list of uploaded files.
Exceptions
- ArgumentNullException
-
sourcePath
is null. - ArgumentException
-
destinationPath
is null or contains only whitespace. - SftpPathNotFoundException
-
destinationPath
was not found on the remote host. - SshException
-
If a problem occurs while copying the file.
UploadFile(Stream, string, Action<ulong>?)
Uploads stream into remote file.
void UploadFile(Stream input, string path, Action<ulong>? uploadCallback = null)
Parameters
input
Stream-
Data input stream.
path
string-
Remote file path.
uploadCallback
Action<ulong>?-
The upload callback.
Remarks
Method calls made by this method to input
, may under certain conditions result in exceptions thrown by the stream.
Exceptions
- ArgumentNullException
-
input
is null. - ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to upload the file was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
UploadFile(Stream, string, bool, Action<ulong>?)
Uploads stream into remote file.
void UploadFile(Stream input, string path, bool canOverride, Action<ulong>? uploadCallback = null)
Parameters
input
Stream-
Data input stream.
path
string-
Remote file path.
canOverride
bool-
if set to true then existing file will be overwritten.
uploadCallback
Action<ulong>?-
The upload callback.
Remarks
Method calls made by this method to input
, may under certain conditions result in exceptions thrown by the stream.
Exceptions
- ArgumentNullException
-
input
is null. - ArgumentException
-
path
is null or contains only whitespace characters. - SshConnectionException
-
Client is not connected.
- SftpPermissionDeniedException
-
Permission to upload the file was denied by the remote host.
-or-
A SSH command was denied by the server. - SshException
-
A SSH error where System.Exception.Message is the message from the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
WriteAllBytes(string, byte[])
Writes the specified byte array to the specified file, and closes the file.
void WriteAllBytes(string path, byte[] bytes)
Parameters
Remarks
If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
If the target file does not exist, it is created.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
WriteAllLines(string, IEnumerable<string>)
Writes a collection of strings to the file using the UTF-8 encoding, and closes the file.
void WriteAllLines(string path, IEnumerable<string> contents)
Parameters
path
string-
The file to write to.
contents
IEnumerable<string>-
The lines to write to the file.
Remarks
The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
If the target file does not exist, it is created.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
WriteAllLines(string, IEnumerable<string>, Encoding)
Writes a collection of strings to the file using the specified encoding, and closes the file.
void WriteAllLines(string path, IEnumerable<string> contents, Encoding encoding)
Parameters
path
string-
The file to write to.
contents
IEnumerable<string>-
The lines to write to the file.
encoding
Encoding-
The character encoding to use.
Remarks
If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
If the target file does not exist, it is created.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
WriteAllLines(string, string[])
Write the specified string array to the file using the UTF-8 encoding, and closes the file.
void WriteAllLines(string path, string[] contents)
Parameters
Remarks
The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
If the target file does not exist, it is created.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
WriteAllLines(string, string[], Encoding)
Writes the specified string array to the file by using the specified encoding, and closes the file.
void WriteAllLines(string path, string[] contents, Encoding encoding)
Parameters
path
string-
The file to write to.
contents
string[]-
The string array to write to the file.
encoding
Encoding-
An System.Text.Encoding object that represents the character encoding applied to the string array.
Remarks
If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
If the target file does not exist, it is created.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
WriteAllText(string, string)
Writes the specified string to the file using the UTF-8 encoding, and closes the file.
void WriteAllText(string path, string contents)
Parameters
Remarks
The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
If the target file does not exist, it is created.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.
WriteAllText(string, string, Encoding)
Writes the specified string to the file using the specified encoding, and closes the file.
void WriteAllText(string path, string contents, Encoding encoding)
Parameters
path
string-
The file to write to.
contents
string-
The string to write to the file.
encoding
Encoding-
The encoding to apply to the string.
Remarks
If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
If the target file does not exist, it is created.
Exceptions
- ArgumentNullException
-
path
is null. - SshConnectionException
-
Client is not connected.
- SftpPathNotFoundException
-
The specified path is invalid, or its directory was not found on the remote host.
- ObjectDisposedException
-
The method was called after the client was disposed.