<PackageReference Include="SSH.NET" Version="2024.2.0" />

SftpClient

Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
public uint BufferSize { get; set; }

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

public TimeSpan OperationTimeout { get; set; }

Gets or sets the operation timeout.

public int ProtocolVersion { get; }

Gets sftp protocol version.

public string WorkingDirectory { get; }

Gets remote working directory.

public SftpClient(ConnectionInfo connectionInfo)

Initializes a new instance of the SftpClient class.

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

Initializes a new instance of the SftpClient class.

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

Initializes a new instance of the SftpClient class.

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

Initializes a new instance of the SftpClient class.

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

Initializes a new instance of the SftpClient class.

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

Appends lines to a file, creating the file if it does not already exist.

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

Appends lines to a file by using a specified encoding, creating the file if it does not already exist.

public void AppendAllText(string path, string contents)

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)

Appends the specified string to the file, creating the file if it does not already exist.

public StreamWriter AppendText(string path)

Creates a 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, Encoding encoding)

Creates a StreamWriter that appends text to a file using the specified encoding, creating the file if it does not already exist.

public IAsyncResult BeginDownloadFile(string path, Stream output)

Begins an asynchronous file downloading into the stream.

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

Begins an asynchronous file downloading into the stream.

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

Begins an asynchronous file downloading into the stream.

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

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

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

Begins the synchronize directories.

public IAsyncResult BeginUploadFile(Stream input, string path)

Begins an asynchronous uploading the stream into remote file.

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

Begins an asynchronous uploading the stream into remote file.

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

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)

Begins an asynchronous uploading the stream into remote file.

public void ChangeDirectory(string path)

Changes remote directory to path.

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

Asynchronously requests to change the current working directory to the specified path.

public void ChangePermissions(string path, short mode)

Changes permissions of file(s) to specified mode.

public SftpFileStream Create(string path)

Creates or overwrites a file in the specified path.

public SftpFileStream Create(string path, int bufferSize)

Creates or overwrites the specified file.

public void CreateDirectory(string path)

Creates remote directory specified by path.

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

Asynchronously requests to create a remote directory specified by path.

public StreamWriter CreateText(string path)

Creates or opens a file for writing UTF-8 encoded text.

public StreamWriter CreateText(string path, Encoding encoding)

Creates or opens a file for writing text using the specified encoding.

public void Delete(string path)

Deletes the specified file or directory.

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

public void DeleteDirectory(string path)

Deletes remote directory specified by path.

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

public void DeleteFile(string path)

Deletes remote file specified by path.

public Task DeleteFileAsync(string path, CancellationToken cancellationToken)

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

Downloads remote file specified by the path into the stream.

public void EndDownloadFile(IAsyncResult asyncResult)

Ends an asynchronous file downloading into the stream.

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

Ends the synchronize directories.

public void EndUploadFile(IAsyncResult asyncResult)

Ends an asynchronous uploading the stream into remote file.

public bool Exists(string path)

Checks whether file or directory exists.

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

Checks whether file or directory exists.

public ISftpFile Get(string path)

Gets reference to remote file or directory.

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

Gets reference to remote file or directory.

public SftpFileAttributes GetAttributes(string path)

Gets the SftpFileAttributes of the file on the path.

public DateTime GetLastAccessTime(string path)

Returns the date and time the specified file or directory was last accessed.

public DateTime GetLastAccessTimeUtc(string path)

Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last accessed.

public DateTime GetLastWriteTime(string path)

Returns the date and time the specified file or directory was last written to.

public DateTime GetLastWriteTimeUtc(string path)

Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last written to.

Gets status using statvfs@openssh.com request.

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

Asynchronously gets status using statvfs@openssh.com request.

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

Retrieves list of files in remote directory.

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

Asynchronously enumerates the files in remote directory.

public SftpFileStream Open(string path, FileMode mode)

Opens a SftpFileStream on the specified path with read/write access.

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

Opens a SftpFileStream on the specified path, with the specified mode and access.

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

Asynchronously opens a SftpFileStream on the specified path, with the specified mode and access.

public SftpFileStream OpenRead(string path)

Opens an existing file for reading.

public StreamReader OpenText(string path)

Opens an existing UTF-8 encoded text file for reading.

public SftpFileStream OpenWrite(string path)

Opens a file for writing.

public byte[] ReadAllBytes(string path)

Opens a binary file, reads the contents of the file into a byte array, and closes the file.

public string[] ReadAllLines(string path)

Opens a text file, reads all lines of the file using UTF-8 encoding, and closes the file.

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

Opens a file, reads all lines of the file with the specified encoding, and closes the file.

public string ReadAllText(string path)

Opens a text file, reads all lines of the file with the UTF-8 encoding, and closes the file.

public string ReadAllText(string path, Encoding encoding)

Opens a file, reads all lines of the file with the specified encoding, and closes the file.

public IEnumerable<string> ReadLines(string path)

Reads the lines of a file with the UTF-8 encoding.

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

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

public void RenameFile(string oldPath, string newPath)

Renames remote file from old path to new path.

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

Renames remote file from old path to new path.

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

Asynchronously renames remote file from old path to new path.

public void SetAttributes(string path, SftpFileAttributes fileAttributes)

Sets the specified SftpFileAttributes of the file on the specified path.

public void SetLastAccessTime(string path, DateTime lastAccessTime)

Sets the date and time the specified file was last accessed.

public void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)

Sets the date and time, in coordinated universal time (UTC), that the specified file was last accessed.

public void SetLastWriteTime(string path, DateTime lastWriteTime)

Sets the date and time that the specified file was last written to.

public void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)

Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.

public void SymbolicLink(string path, string linkPath)

Creates a symbolic link from old path to new path.

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

Synchronizes the directories.

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

Uploads stream into remote file.

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

Uploads stream into remote file.

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

Writes the specified byte array to the specified file, and closes the file.

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

Writes a collection of strings to the file using the UTF-8 encoding, and closes the file.

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

Write the specified string array to the file using the UTF-8 encoding, and closes the file.

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

Writes a collection of strings to the file using the specified encoding, and closes the file.

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

Writes the specified string array to the file by using the specified encoding, and closes the file.

public void WriteAllText(string path, string contents)

Writes the specified string to the file using the UTF-8 encoding, and closes the file.

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

Writes the specified string to the file using the specified encoding, and closes the file.