Movatterモバイル変換


[0]ホーム

URL:


Table of Contents

Class SftpClient

Namespace
Renci.SshNet
Assembly
Renci.SshNet.dll

Implementation of the SSH File Transfer Protocol (SFTP) over SSH.

public class SftpClient : BaseClient, ISftpClient, IBaseClient, IDisposable

Inheritance

object
BaseClient
SftpClient

Implements

ISftpClient
IBaseClient
IDisposable

Inherited Members

BaseClient.ConnectionInfo
BaseClient.IsConnected
BaseClient.KeepAliveInterval
BaseClient.ErrorOccurred
BaseClient.HostKeyReceived
BaseClient.ServerIdentificationReceived
BaseClient.Connect()
BaseClient.ConnectAsync(CancellationToken)
BaseClient.Disconnect()
BaseClient.SendKeepAlive()
BaseClient.OnConnecting()
BaseClient.OnConnected()
BaseClient.OnDisconnecting()
BaseClient.OnDisconnected()
BaseClient.Dispose()
BaseClient.Dispose(bool)
BaseClient.CheckDisposed()
object.Equals(object?)
object.Equals(object?, object?)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object?, object?)
object.ToString()

Constructors

SftpClient(ConnectionInfo)

Initializes a new instance of theRenci.SshNet.SftpClient class.

public SftpClient(ConnectionInfo connectionInfo)

Parameters

connectionInfoConnectionInfo

The connection info.

Exceptions

ArgumentNullException

connectionInfo isnull.

SftpClient(string, int, string, string)

Initializes a new instance of theRenci.SshNet.SftpClient class.

[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]public SftpClient(string host, int port, string username, string password)

Parameters

hoststring

Connection host.

portint

Connection port.

usernamestring

Authentication username.

passwordstring

Authentication password.

Exceptions

ArgumentNullException

password isnull.

ArgumentException

host is invalid.

-or-

username isnull or contains only whitespace characters.
ArgumentOutOfRangeException

port is not withinSystem.Net.IPEndPoint.MinPort andSystem.Net.IPEndPoint.MaxPort.

SftpClient(string, string, string)

Initializes a new instance of theRenci.SshNet.SftpClient class.

public SftpClient(string host, string username, string password)

Parameters

hoststring

Connection host.

usernamestring

Authentication username.

passwordstring

Authentication password.

Exceptions

ArgumentNullException

password isnull.

ArgumentException

host is invalid.

-or-

username isnull contains only whitespace characters.

SftpClient(string, int, string, params IPrivateKeySource[])

Initializes a new instance of theRenci.SshNet.SftpClient class.

[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]public SftpClient(string host, int port, string username, params IPrivateKeySource[] keyFiles)

Parameters

hoststring

Connection host.

portint

Connection port.

usernamestring

Authentication username.

keyFilesIPrivateKeySource[]

Authentication private key file(s) .

Exceptions

ArgumentNullException

keyFiles isnull.

ArgumentException

host is invalid.

-or-

username isnull or contains only whitespace characters.
ArgumentOutOfRangeException

port is not withinSystem.Net.IPEndPoint.MinPort andSystem.Net.IPEndPoint.MaxPort.

SftpClient(string, string, params IPrivateKeySource[])

Initializes a new instance of theRenci.SshNet.SftpClient class.

public SftpClient(string host, string username, params IPrivateKeySource[] keyFiles)

Parameters

hoststring

Connection host.

usernamestring

Authentication username.

keyFilesIPrivateKeySource[]

Authentication private key file(s) .

Exceptions

ArgumentNullException

keyFiles isnull.

ArgumentException

host is invalid.

-or-

username isnull or contains only whitespace characters.

Properties

BufferSize

Gets or sets the maximum size of the buffer in bytes.

public uint BufferSize { get; set; }

Property Value

uint

Remarks

For write operations, this limits the size of the payload forindividual SSH_FXP_WRITE messages. The actual size is alwayscapped 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 whichis requested from the peer in a SSH_FXP_READ message. The peerwill 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 theSSH_FXP_DATA protocol fields.

The size of the each individual SSH_FXP_DATA message is limited to thelocal maximum packet size of the channel, which is set to64 KBfor SSH.NET. However, the peer can limit this even further.

Exceptions

ObjectDisposedException

The method was called after the client was disposed.

IsConnected

Gets a value indicating whether this client is connected to the server andthe SFTP session is open.

public override bool IsConnected { get; }

Property Value

bool

Exceptions

ObjectDisposedException

The method was called after the client was disposed.

OperationTimeout

Gets or sets the operation timeout.

public TimeSpan OperationTimeout { get; set; }

Property Value

TimeSpan

Exceptions

ArgumentOutOfRangeException

value represents a value that is less than -1 or greater thanSystem.Int32.MaxValue milliseconds.

ProtocolVersion

Gets sftp protocol version.

public int ProtocolVersion { get; }

Property Value

int

Exceptions

SshConnectionException

Client is not connected.

ObjectDisposedException

The method was called after the client was disposed.

WorkingDirectory

Gets remote working directory.

public string WorkingDirectory { get; }

Property Value

string

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.

public void AppendAllLines(string path, IEnumerable<string> contents)

Parameters

pathstring

The file to append the lines to. The file is created if it does not already exist.

contentsIEnumerable<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 isnull.

-or-

contents isnull.
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.

public void AppendAllLines(string path, IEnumerable<string> contents, Encoding encoding)

Parameters

pathstring

The file to append the lines to. The file is created if it does not already exist.

contentsIEnumerable<string>

The lines to append to the file.

encodingEncoding

The character encoding to use.

Exceptions

ArgumentNullException

path isnull.

-or-

contents isnull.

-or-

encoding isnull.
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.

public void AppendAllText(string path, string contents)

Parameters

pathstring

The file to append the specified string to.

contentsstring

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 isnull.

-or-

contents isnull.
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.

public void AppendAllText(string path, string contents, Encoding encoding)

Parameters

pathstring

The file to append the specified string to.

contentsstring

The string to append to the file.

encodingEncoding

The character encoding to use.

Exceptions

ArgumentNullException

path isnull.

-or-

contents isnull.

-or-

encoding isnull.
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 aSystem.IO.StreamWriter that appends UTF-8 encoded text to the specified file,creating the file if it does not already exist.

public StreamWriter AppendText(string path)

Parameters

pathstring

The path to the file to append to.

Returns

StreamWriter

ASystem.IO.StreamWriter that appends text to a file using UTF-8 encoding without aByte-Order Mark (BOM).

Exceptions

ArgumentNullException

path isnull.

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 aSystem.IO.StreamWriter that appends text to a file using the specifiedencoding, creating the file if it does not already exist.

public StreamWriter AppendText(string path, Encoding encoding)

Parameters

pathstring

The path to the file to append to.

encodingEncoding

The character encoding to use.

Returns

StreamWriter

ASystem.IO.StreamWriter that appends text to a file using the specified encoding.

Exceptions

ArgumentNullException

path isnull.

-or-

encoding isnull.
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.

public IAsyncResult BeginDownloadFile(string path, Stream output)

Parameters

pathstring

The path.

outputStream

The output.

Returns

IAsyncResult

AnSystem.IAsyncResult that references the asynchronous operation.

Remarks

Method calls made by this method tooutput, may under certain conditions result in exceptions thrown by the stream.

Exceptions

ArgumentNullException

output isnull.

ArgumentException

path isnull 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 whereSystem.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.

public IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback? asyncCallback)

Parameters

pathstring

The path.

outputStream

The output.

asyncCallbackAsyncCallback?

The method to be called when the asynchronous write operation is completed.

Returns

IAsyncResult

AnSystem.IAsyncResult that references the asynchronous operation.

Remarks

Method calls made by this method tooutput, may under certain conditions result in exceptions thrown by the stream.

Exceptions

ArgumentNullException

output isnull.

ArgumentException

path isnull 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 whereSystem.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.

public IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback? asyncCallback, object? state, Action<ulong>? downloadCallback = null)

Parameters

pathstring

The path.

outputStream

The output.

asyncCallbackAsyncCallback?

The method to be called when the asynchronous write operation is completed.

stateobject?

A user-provided object that distinguishes this particular asynchronous write request from other requests.

downloadCallbackAction<ulong>?

The download callback.

Returns

IAsyncResult

AnSystem.IAsyncResult that references the asynchronous operation.

Remarks

Method calls made by this method tooutput, may under certain conditions result in exceptions thrown by the stream.

Exceptions

ArgumentNullException

output isnull.

ArgumentException

path isnull 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.

public IAsyncResult BeginListDirectory(string path, AsyncCallback? asyncCallback, object? state, Action<int>? listCallback = null)

Parameters

pathstring

The path.

asyncCallbackAsyncCallback?

The method to be called when the asynchronous write operation is completed.

stateobject?

A user-provided object that distinguishes this particular asynchronous write request from other requests.

listCallbackAction<int>?

The list callback.

Returns

IAsyncResult

AnSystem.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.

public IAsyncResult BeginSynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern, AsyncCallback? asyncCallback, object? state)

Parameters

sourcePathstring

The source path.

destinationPathstring

The destination path.

searchPatternstring

The search pattern.

asyncCallbackAsyncCallback?

The async callback.

stateobject?

The state.

Returns

IAsyncResult

AnSystem.IAsyncResult that represents the asynchronous directory synchronization.

Exceptions

ArgumentNullException

sourcePath orsearchPattern isnull.

ArgumentException

destinationPath isnull 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.

public IAsyncResult BeginUploadFile(Stream input, string path)

Parameters

inputStream

Data input stream.

pathstring

Remote file path.

Returns

IAsyncResult

AnSystem.IAsyncResult that references the asynchronous operation.

Remarks

Method calls made by this method toinput, 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 isnull.

ArgumentException

path isnull 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 whereSystem.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.

public IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback? asyncCallback)

Parameters

inputStream

Data input stream.

pathstring

Remote file path.

asyncCallbackAsyncCallback?

The method to be called when the asynchronous write operation is completed.

Returns

IAsyncResult

AnSystem.IAsyncResult that references the asynchronous operation.

Remarks

Method calls made by this method toinput, 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 isnull.

ArgumentException

path isnull 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 whereSystem.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.

public IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback? asyncCallback, object? state, Action<ulong>? uploadCallback = null)

Parameters

inputStream

Data input stream.

pathstring

Remote file path.

asyncCallbackAsyncCallback?

The method to be called when the asynchronous write operation is completed.

stateobject?

A user-provided object that distinguishes this particular asynchronous write request from other requests.

uploadCallbackAction<ulong>?

The upload callback.

Returns

IAsyncResult

AnSystem.IAsyncResult that references the asynchronous operation.

Remarks

Method calls made by this method toinput, 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 isnull.

ArgumentException

path isnull 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 whereSystem.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.

public IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride, AsyncCallback? asyncCallback, object? state, Action<ulong>? uploadCallback = null)

Parameters

inputStream

Data input stream.

pathstring

Remote file path.

canOverridebool

Specified whether an existing file can be overwritten.

asyncCallbackAsyncCallback?

The method to be called when the asynchronous write operation is completed.

stateobject?

A user-provided object that distinguishes this particular asynchronous write request from other requests.

uploadCallbackAction<ulong>?

The upload callback.

Returns

IAsyncResult

AnSystem.IAsyncResult that references the asynchronous operation.

Remarks

Method calls made by this method toinput, may under certain conditions result in exceptions thrown by the stream.

Whenpath refers to an existing file, setcanOverride totrue to overwrite and truncate that file.IfcanOverride isfalse, the upload will fail andRenci.SshNet.SftpClient.EndUploadFile(System.IAsyncResult) will throw anRenci.SshNet.Common.SshException.

Exceptions

ArgumentNullException

input isnull.

ArgumentException

path isnull or contains only whitespace characters.

ObjectDisposedException

The method was called after the client was disposed.

ChangeDirectory(string)

Changes remote directory to path.

public void ChangeDirectory(string path)

Parameters

pathstring

New directory path.

Exceptions

ArgumentNullException

path isnull.

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 whereSystem.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.

public Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken = default)

Parameters

pathstring

The new working directory.

cancellationTokenCancellationToken

The token to monitor for cancellation requests.

Returns

Task

ASystem.Threading.Tasks.Task that tracks the asynchronous change working directory request.

Exceptions

ArgumentNullException

path isnull.

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 whereSystem.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.

public void ChangePermissions(string path, short mode)

Parameters

pathstring

File(s) path, may match multiple files.

modeshort

The mode.

Exceptions

ArgumentNullException

path isnull.

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 whereSystem.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.

public SftpFileStream Create(string path)

Parameters

pathstring

The path and name of the file to create.

Returns

SftpFileStream

ARenci.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 isnull.

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.

public SftpFileStream Create(string path, int bufferSize)

Parameters

pathstring

The path and name of the file to create.

bufferSizeint

The maximum number of bytes buffered for reads and writes to the file.

Returns

SftpFileStream

ARenci.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 isnull.

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.

public void CreateDirectory(string path)

Parameters

pathstring

Directory path to create.

Exceptions

ArgumentException

path isnull 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 whereSystem.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.

public Task CreateDirectoryAsync(string path, CancellationToken cancellationToken = default)

Parameters

pathstring

Directory path to create.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task

ASystem.Threading.Tasks.Task that represents the asynchronous create directory operation.

Exceptions

ArgumentException

path isnull 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 whereSystem.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.

public StreamWriter CreateText(string path)

Parameters

pathstring

The file to be opened for writing.

Returns

StreamWriter

ASystem.IO.StreamWriter that writes text to a file using UTF-8 encoding withouta Byte-Order Mark (BOM).

Remarks

If the file specified bypath does not exist, it is created.If the file does exist, its contents are replaced.

Exceptions

ArgumentNullException

path isnull.

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.

public StreamWriter CreateText(string path, Encoding encoding)

Parameters

pathstring

The file to be opened for writing.

encodingEncoding

The character encoding to use.

Returns

StreamWriter

ASystem.IO.StreamWriter that writes to a file using the specified encoding.

Remarks

If the file specified bypath does not exist, it is created.If the file does exist, its contents are replaced.

Exceptions

ArgumentNullException

path isnull.

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.

public void Delete(string path)

Parameters

pathstring

The name of the file or directory to be deleted. Wildcard characters are not supported.

Exceptions

ArgumentNullException

path isnull.

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.

public Task DeleteAsync(string path, CancellationToken cancellationToken = default)

Parameters

pathstring

The name of the file or directory to be deleted. Wildcard characters are not supported.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task

ASystem.Threading.Tasks.Task that represents the asynchronous delete operation.

DeleteDirectory(string)

Deletes remote directory specified by path.

public void DeleteDirectory(string path)

Parameters

pathstring

Directory to be deleted path.

Exceptions

ArgumentException

path isnull 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 whereSystem.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.

public Task DeleteDirectoryAsync(string path, CancellationToken cancellationToken = default)

Parameters

pathstring

The path of the directory to be deleted.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task

ASystem.Threading.Tasks.Task that represents the asynchronous delete operation.

Exceptions

ArgumentException

path isnull 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 whereSystem.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.

public void DeleteFile(string path)

Parameters

pathstring

File to be deleted path.

Exceptions

ArgumentException

path isnull 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 whereSystem.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.

public Task DeleteFileAsync(string path, CancellationToken cancellationToken)

Parameters

pathstring

File to be deleted path.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task

ASystem.Threading.Tasks.Task that represents the asynchronous delete operation.

Exceptions

ArgumentException

path isnull 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 whereSystem.Exception.Message is the message from the remote host.

ObjectDisposedException

The method was called after the client was disposed.

Dispose(bool)

Releases unmanaged and - optionally - managed resources.

protected override void Dispose(bool disposing)

Parameters

disposingbool

true to release both managed and unmanaged resources;false to release only unmanaged resources.

DownloadFile(string, Stream, Action<ulong>?)

Downloads a remote file into aSystem.IO.Stream.

public void DownloadFile(string path, Stream output, Action<ulong>? downloadCallback = null)

Parameters

pathstring

The path to the remote file.

outputStream

TheSystem.IO.Stream to write the file into.

downloadCallbackAction<ulong>?

The download callback.

Exceptions

ArgumentNullException

output orpath isnull.

ArgumentException

path is empty or contains only whitespace characters.

SshConnectionException

Client is not connected.

SftpPermissionDeniedException

Permission to perform the operation was denied by the remote host.

-or-

An SSH command was denied by the server.
SftpPathNotFoundException

path was not found on the remote host.

SshException

An SSH error whereSystem.Exception.Message is the message from the remote host.

ObjectDisposedException

The method was called after the client was disposed.

DownloadFileAsync(string, Stream, CancellationToken)

Asynchronously downloads a remote file into aSystem.IO.Stream.

public Task DownloadFileAsync(string path, Stream output, CancellationToken cancellationToken = default)

Parameters

pathstring

The path to the remote file.

outputStream

TheSystem.IO.Stream to write the file into.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task

ASystem.Threading.Tasks.Task that represents the asynchronous download operation.

Exceptions

ArgumentNullException

output orpath isnull.

ArgumentException

path is empty or contains only whitespace characters.

SshConnectionException

Client is not connected.

SftpPermissionDeniedException

Permission to perform the operation was denied by the remote host.

-or-

An SSH command was denied by the server.
SftpPathNotFoundException

path was not found on the remote host.

SshException

An SSH error whereSystem.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.

public void EndDownloadFile(IAsyncResult asyncResult)

Parameters

asyncResultIAsyncResult

The pending asynchronous SFTP request.

Exceptions

ArgumentException

TheSystem.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 sameSystem.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 whereSystem.Exception.Message is the message from the remote host.

EndListDirectory(IAsyncResult)

Ends an asynchronous operation of retrieving list of files in remote directory.

public IEnumerable<ISftpFile> EndListDirectory(IAsyncResult asyncResult)

Parameters

asyncResultIAsyncResult

The pending asynchronous SFTP request.

Returns

IEnumerable<ISftpFile>

A list of files.

Exceptions

ArgumentException

TheSystem.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 sameSystem.IAsyncResult.

EndSynchronizeDirectories(IAsyncResult)

Ends the synchronize directories.

public IEnumerable<FileInfo> EndSynchronizeDirectories(IAsyncResult asyncResult)

Parameters

asyncResultIAsyncResult

The async result.

Returns

IEnumerable<FileInfo>

A list of uploaded files.

Exceptions

ArgumentException

TheSystem.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 sameSystem.IAsyncResult.
SftpPathNotFoundException

The destination path was not found on the remote host.

EndUploadFile(IAsyncResult)

Ends an asynchronous uploading the stream into remote file.

public void EndUploadFile(IAsyncResult asyncResult)

Parameters

asyncResultIAsyncResult

The pending asynchronous SFTP request.

Exceptions

ArgumentException

TheSystem.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 sameSystem.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 whereSystem.Exception.Message is the message from the remote host.

Exists(string)

Checks whether file or directory exists.

public bool Exists(string path)

Parameters

pathstring

The path.

Returns

bool

true if directory or file exists; otherwisefalse.

Exceptions

ArgumentException

path isnull 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 whereSystem.Exception.Message is the message from the remote host.

ObjectDisposedException

The method was called after the client was disposed.

ExistsAsync(string, CancellationToken)

Checks whether file or directory exists.

public Task<bool> ExistsAsync(string path, CancellationToken cancellationToken = default)

Parameters

pathstring

The path.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task<bool>

ASystem.Threading.Tasks.Task`1 that represents the exists operation.The task result containstrue if directory or file exists; otherwisefalse.

Exceptions

ArgumentException

path isnull 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 whereSystem.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.

public ISftpFile Get(string path)

Parameters

pathstring

The path.

Returns

ISftpFile

A reference toRenci.SshNet.Sftp.ISftpFile file object.

Exceptions

SshConnectionException

Client is not connected.

SftpPathNotFoundException

path was not found on the remote host.

ArgumentNullException

path isnull.

ObjectDisposedException

The method was called after the client was disposed.

GetAsync(string, CancellationToken)

Gets reference to remote file or directory.

public Task<ISftpFile> GetAsync(string path, CancellationToken cancellationToken)

Parameters

pathstring

The path.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task<ISftpFile>

ASystem.Threading.Tasks.Task`1 that represents the get operation.The task result contains the reference toRenci.SshNet.Sftp.ISftpFile file object.

Exceptions

SshConnectionException

Client is not connected.

SftpPathNotFoundException

path was not found on the remote host.

ArgumentNullException

path isnull.

ObjectDisposedException

The method was called after the client was disposed.

GetAttributes(string)

Gets theRenci.SshNet.Sftp.SftpFileAttributes of the file on the path.

public SftpFileAttributes GetAttributes(string path)

Parameters

pathstring

The path to the file.

Returns

SftpFileAttributes

TheRenci.SshNet.Sftp.SftpFileAttributes of the file on the path.

Exceptions

ArgumentNullException

path isnull.

SshConnectionException

Client is not connected.

SftpPathNotFoundException

path was not found on the remote host.

ObjectDisposedException

The method was called after the client was disposed.

GetAttributesAsync(string, CancellationToken)

Gets theRenci.SshNet.Sftp.SftpFileAttributes of the file on the path.

public Task<SftpFileAttributes> GetAttributesAsync(string path, CancellationToken cancellationToken)

Parameters

pathstring

The path to the file.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task<SftpFileAttributes>

ASystem.Threading.Tasks.Task`1 that represents the attribute retrieval operation.The task result contains theRenci.SshNet.Sftp.SftpFileAttributes of the file on the path.

Exceptions

ArgumentNullException

path isnull.

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.

public DateTime GetLastAccessTime(string path)

Parameters

pathstring

The file or directory for which to obtain access date and time information.

Returns

DateTime

ASystem.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 isnull.

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.

public DateTime GetLastAccessTimeUtc(string path)

Parameters

pathstring

The file or directory for which to obtain access date and time information.

Returns

DateTime

ASystem.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 isnull.

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.

public DateTime GetLastWriteTime(string path)

Parameters

pathstring

The file or directory for which to obtain write date and time information.

Returns

DateTime

ASystem.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 isnull.

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.

public DateTime GetLastWriteTimeUtc(string path)

Parameters

pathstring

The file or directory for which to obtain write date and time information.

Returns

DateTime

ASystem.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 isnull.

SshConnectionException

Client is not connected.

ObjectDisposedException

The method was called after the client was disposed.

GetStatus(string)

Gets status using statvfs@openssh.com request.

public SftpFileSystemInformation GetStatus(string path)

Parameters

pathstring

The path.

Returns

SftpFileSystemInformation

ARenci.SshNet.Sftp.SftpFileSystemInformation instance that contains file status information.

Exceptions

SshConnectionException

Client is not connected.

ArgumentNullException

path isnull.

ObjectDisposedException

The method was called after the client was disposed.

GetStatusAsync(string, CancellationToken)

Asynchronously gets status using statvfs@openssh.com request.

public Task<SftpFileSystemInformation> GetStatusAsync(string path, CancellationToken cancellationToken)

Parameters

pathstring

The path.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task<SftpFileSystemInformation>

ASystem.Threading.Tasks.Task`1 that represents the status operation.The task result contains theRenci.SshNet.Sftp.SftpFileSystemInformation instance that contains file status information.

Exceptions

SshConnectionException

Client is not connected.

ArgumentNullException

path isnull.

ObjectDisposedException

The method was called after the client was disposed.

ListDirectory(string, Action<int>?)

Retrieves list of files in remote directory.

public IEnumerable<ISftpFile> ListDirectory(string path, Action<int>? listCallback = null)

Parameters

pathstring

The path.

listCallbackAction<int>?

The list callback.

Returns

IEnumerable<ISftpFile>

A list of files.

Exceptions

ArgumentNullException

path isnull.

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 whereSystem.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.

public IAsyncEnumerable<ISftpFile> ListDirectoryAsync(string path, CancellationToken cancellationToken)

Parameters

pathstring

The path.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

IAsyncEnumerable<ISftpFile>

AnSystem.Collections.Generic.IAsyncEnumerable`1 ofRenci.SshNet.Sftp.ISftpFile that represents the asynchronous enumeration operation.The enumeration contains an async stream ofRenci.SshNet.Sftp.ISftpFile for the files in the directory specified bypath.

Exceptions

ArgumentNullException

path isnull.

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 whereSystem.Exception.Message is the message from the remote host.

ObjectDisposedException

The method was called after the client was disposed.

OnConnected()

Called when client is connected to the server.

protected override void OnConnected()

OnDisconnecting()

Called when client is disconnecting from the server.

protected override void OnDisconnecting()

Open(string, FileMode)

Opens aRenci.SshNet.Sftp.SftpFileStream on the specified path with read/write access.

public SftpFileStream Open(string path, FileMode mode)

Parameters

pathstring

The file to open.

modeFileMode

ASystem.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 unsharedRenci.SshNet.Sftp.SftpFileStream that provides access to the specified file, with the specified mode and read/write access.

Exceptions

ArgumentNullException

path isnull.

SshConnectionException

Client is not connected.

ObjectDisposedException

The method was called after the client was disposed.

Open(string, FileMode, FileAccess)

Opens aRenci.SshNet.Sftp.SftpFileStream on the specified path, with the specified mode and access.

public SftpFileStream Open(string path, FileMode mode, FileAccess access)

Parameters

pathstring

The file to open.

modeFileMode

ASystem.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.

accessFileAccess

ASystem.IO.FileAccess value that specifies the operations that can be performed on the file.

Returns

SftpFileStream

An unsharedRenci.SshNet.Sftp.SftpFileStream that provides access to the specified file, with the specified mode and access.

Exceptions

ArgumentNullException

path isnull.

SshConnectionException

Client is not connected.

ObjectDisposedException

The method was called after the client was disposed.

OpenAsync(string, FileMode, FileAccess, CancellationToken)

Asynchronously opens aRenci.SshNet.Sftp.SftpFileStream on the specified path, with the specified mode and access.

public Task<SftpFileStream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken)

Parameters

pathstring

The file to open.

modeFileMode

ASystem.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.

accessFileAccess

ASystem.IO.FileAccess value that specifies the operations that can be performed on the file.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task<SftpFileStream>

ASystem.Threading.Tasks.Task`1 that represents the asynchronous open operation.The task result contains theRenci.SshNet.Sftp.SftpFileStream that provides access to the specified file, with the specified mode and access.

Exceptions

ArgumentNullException

path isnull.

SshConnectionException

Client is not connected.

ObjectDisposedException

The method was called after the client was disposed.

OpenRead(string)

Opens an existing file for reading.

public SftpFileStream OpenRead(string path)

Parameters

pathstring

The file to be opened for reading.

Returns

SftpFileStream

A read-onlyRenci.SshNet.Sftp.SftpFileStream on the specified path.

Exceptions

ArgumentNullException

path isnull.

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.

public StreamReader OpenText(string path)

Parameters

pathstring

The file to be opened for reading.

Returns

StreamReader

ASystem.IO.StreamReader on the specified path.

Exceptions

ArgumentNullException

path isnull.

SshConnectionException

Client is not connected.

ObjectDisposedException

The method was called after the client was disposed.

OpenWrite(string)

Opens a file for writing.

public SftpFileStream OpenWrite(string path)

Parameters

pathstring

The file to be opened for writing.

Returns

SftpFileStream

An unsharedRenci.SshNet.Sftp.SftpFileStream object on the specified path withSystem.IO.FileAccess.Write access.

Remarks

If the file does not exist, it is created.

Exceptions

ArgumentNullException

path isnull.

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.

public byte[] ReadAllBytes(string path)

Parameters

pathstring

The file to open for reading.

Returns

byte[]

A byte array containing the contents of the file.

Exceptions

ArgumentNullException

path isnull.

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.

public string[] ReadAllLines(string path)

Parameters

pathstring

The file to open for reading.

Returns

string[]

A string array containing all lines of the file.

Exceptions

ArgumentNullException

path isnull.

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.

public string[] ReadAllLines(string path, Encoding encoding)

Parameters

pathstring

The file to open for reading.

encodingEncoding

The encoding applied to the contents of the file.

Returns

string[]

A string array containing all lines of the file.

Exceptions

ArgumentNullException

path isnull.

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.

public string ReadAllText(string path)

Parameters

pathstring

The file to open for reading.

Returns

string

A string containing all lines of the file.

Exceptions

ArgumentNullException

path isnull.

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.

public string ReadAllText(string path, Encoding encoding)

Parameters

pathstring

The file to open for reading.

encodingEncoding

The encoding applied to the contents of the file.

Returns

string

A string containing all lines of the file.

Exceptions

ArgumentNullException

path isnull.

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.

public IEnumerable<string> ReadLines(string path)

Parameters

pathstring

The file to read.

Returns

IEnumerable<string>

The lines of the file.

Remarks

The lines are enumerated lazily. The opening of the file and any resulting exceptions occurupon enumeration.

Exceptions

ArgumentNullException

path isnull. Thrown eagerly.

SshConnectionException

Client is not connected upon enumeration.

ObjectDisposedException

The return value is enumerated after the client is disposed.

ReadLines(string, Encoding)

Read the lines of a file that has a specified encoding.

public IEnumerable<string> ReadLines(string path, Encoding encoding)

Parameters

pathstring

The file to read.

encodingEncoding

The encoding that is applied to the contents of the file.

Returns

IEnumerable<string>

The lines of the file.

Remarks

The lines are enumerated lazily. The opening of the file and any resulting exceptions occurupon enumeration.

Exceptions

ArgumentNullException

path isnull. Thrown eagerly.

SshConnectionException

Client is not connected upon enumeration.

ObjectDisposedException

The return value is enumerated after the client is disposed.

RenameFile(string, string)

Renames remote file from old path to new path.

public void RenameFile(string oldPath, string newPath)

Parameters

oldPathstring

Path to the old file location.

newPathstring

Path to the new file location.

Exceptions

ArgumentNullException

oldPath isnull.

-or-

ornewPath isnull.
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 whereSystem.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.

public void RenameFile(string oldPath, string newPath, bool isPosix)

Parameters

oldPathstring

Path to the old file location.

newPathstring

Path to the new file location.

isPosixbool

if set totrue then perform a posix rename.

Exceptions

ArgumentNullException

oldPath isnull.

-or-

ornewPath isnull.
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 whereSystem.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.

public Task RenameFileAsync(string oldPath, string newPath, CancellationToken cancellationToken)

Parameters

oldPathstring

Path to the old file location.

newPathstring

Path to the new file location.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task

ASystem.Threading.Tasks.Task that represents the asynchronous rename operation.

Exceptions

ArgumentNullException

oldPath isnull.

-or-

ornewPath isnull.
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 whereSystem.Exception.Message is the message from the remote host.

ObjectDisposedException

The method was called after the client was disposed.

SetAttributes(string, SftpFileAttributes)

Sets the specifiedRenci.SshNet.Sftp.SftpFileAttributes of the file on the specified path.

public void SetAttributes(string path, SftpFileAttributes fileAttributes)

Parameters

pathstring

The path to the file.

fileAttributesSftpFileAttributes

The desiredRenci.SshNet.Sftp.SftpFileAttributes.

Exceptions

ArgumentNullException

path isnull.

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.

public void SetLastAccessTime(string path, DateTime lastAccessTime)

Parameters

pathstring

The file for which to set the access date and time information.

lastAccessTimeDateTime

ASystem.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.

public void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)

Parameters

pathstring

The file for which to set the access date and time information.

lastAccessTimeUtcDateTime

ASystem.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.

public void SetLastWriteTime(string path, DateTime lastWriteTime)

Parameters

pathstring

The file for which to set the date and time information.

lastWriteTimeDateTime

ASystem.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.

public void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)

Parameters

pathstring

The file for which to set the date and time information.

lastWriteTimeUtcDateTime

ASystem.DateTime containing the value to set for the last write date and time of path. This value is expressed in UTC time.

Creates a symbolic link from old path to new path.

public void SymbolicLink(string path, string linkPath)

Parameters

pathstring

The old path.

linkPathstring

The new path.

Exceptions

ArgumentException

path isnull.

-or-

linkPath isnull 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 whereSystem.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.

public IEnumerable<FileInfo> SynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern)

Parameters

sourcePathstring

The source path.

destinationPathstring

The destination path.

searchPatternstring

The search pattern.

Returns

IEnumerable<FileInfo>

A list of uploaded files.

Exceptions

ArgumentNullException

sourcePath isnull.

ArgumentException

destinationPath isnull 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 aSystem.IO.Stream to a remote file path.

public void UploadFile(Stream input, string path, Action<ulong>? uploadCallback = null)

Parameters

inputStream

TheSystem.IO.Stream to write to the remote path.

pathstring

The remote file path to write to.

uploadCallbackAction<ulong>?

The upload callback.

Exceptions

ArgumentNullException

input orpath isnull.

ArgumentException

path is empty or contains only whitespace characters.

SshConnectionException

Client is not connected.

SftpPermissionDeniedException

Permission to upload the file was denied by the remote host.

-or-

An SSH command was denied by the server.
SshException

An SSH error whereSystem.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 aSystem.IO.Stream to a remote file path.

public void UploadFile(Stream input, string path, bool canOverride, Action<ulong>? uploadCallback = null)

Parameters

inputStream

TheSystem.IO.Stream to write to the remote path.

pathstring

The remote file path to write to.

canOverridebool

Whether the remote file can be overwritten if it already exists.

uploadCallbackAction<ulong>?

The upload callback.

Exceptions

ArgumentNullException

input orpath isnull.

ArgumentException

path is empty or contains only whitespace characters.

SshConnectionException

Client is not connected.

SftpPermissionDeniedException

Permission to upload the file was denied by the remote host.

-or-

An SSH command was denied by the server.
SshException

An SSH error whereSystem.Exception.Message is the message from the remote host.

ObjectDisposedException

The method was called after the client was disposed.

UploadFileAsync(Stream, string, CancellationToken)

Asynchronously uploads aSystem.IO.Stream to a remote file path.

public Task UploadFileAsync(Stream input, string path, CancellationToken cancellationToken = default)

Parameters

inputStream

TheSystem.IO.Stream to write to the remote path.

pathstring

The remote file path to write to.

cancellationTokenCancellationToken

TheSystem.Threading.CancellationToken to observe.

Returns

Task

ASystem.Threading.Tasks.Task that represents the asynchronous upload operation.

Exceptions

ArgumentNullException

input orpath isnull.

ArgumentException

path is empty or contains only whitespace characters.

SshConnectionException

Client is not connected.

SftpPermissionDeniedException

Permission to upload the file was denied by the remote host.

-or-

An SSH command was denied by the server.
SshException

An SSH error whereSystem.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.

public void WriteAllBytes(string path, byte[] bytes)

Parameters

pathstring

The file to write to.

bytesbyte[]

The bytes to write to the file.

Remarks

If the file specified bypath does not exist, it is created.If the file does exist, its contents are replaced.

Exceptions

ArgumentNullException

path isnull.

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.

public void WriteAllLines(string path, IEnumerable<string> contents)

Parameters

pathstring

The file to write to.

contentsIEnumerable<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 file specified bypath does not exist, it is created.If the file does exist, its contents are replaced.

Exceptions

ArgumentNullException

path isnull.

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.

public void WriteAllLines(string path, string[] contents)

Parameters

pathstring

The file to write to.

contentsstring[]

The string array 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 file specified bypath does not exist, it is created.If the file does exist, its contents are replaced.

Exceptions

ArgumentNullException

path isnull.

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.

public void WriteAllLines(string path, IEnumerable<string> contents, Encoding encoding)

Parameters

pathstring

The file to write to.

contentsIEnumerable<string>

The lines to write to the file.

encodingEncoding

The character encoding to use.

Remarks

If the file specified bypath does not exist, it is created.If the file does exist, its contents are replaced.

Exceptions

ArgumentNullException

path isnull.

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.

public void WriteAllLines(string path, string[] contents, Encoding encoding)

Parameters

pathstring

The file to write to.

contentsstring[]

The string array to write to the file.

encodingEncoding

AnSystem.Text.Encoding object that represents the character encoding applied to the string array.

Remarks

If the file specified bypath does not exist, it is created.If the file does exist, its contents are replaced.

Exceptions

ArgumentNullException

path isnull.

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.

public void WriteAllText(string path, string contents)

Parameters

pathstring

The file to write to.

contentsstring

The string 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 file specified bypath does not exist, it is created.If the file does exist, its contents are replaced.

Exceptions

ArgumentNullException

path isnull.

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.

public void WriteAllText(string path, string contents, Encoding encoding)

Parameters

pathstring

The file to write to.

contentsstring

The string to write to the file.

encodingEncoding

The encoding to apply to the string.

Remarks

If the file specified bypath does not exist, it is created.If the file does exist, its contents are replaced.

Exceptions

ArgumentNullException

path isnull.

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.


[8]ページ先頭

©2009-2025 Movatter.jp