Table of Contents

Class SftpDirectoryExtensions

Namespace
Tmds.Ssh
Assembly
Tmds.Ssh.dll

Extension methods for ISftpDirectory.

public static class SftpDirectoryExtensions
Inheritance
SftpDirectoryExtensions
Inherited Members

Methods

CreateDirectoryAsync(ISftpDirectory, string, CancellationToken)

Creates a directory. This does not fail when the directory exists (or is a link to a directory).

public static ValueTask CreateDirectoryAsync(this ISftpDirectory directory, string path, CancellationToken cancellationToken)

Parameters

directory ISftpDirectory

The working directory.

path string

The directory path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

CreateNewDirectoryAsync(ISftpDirectory, string, CancellationToken)

Creates a new directory. This fails when the directory already exists.

public static ValueTask CreateNewDirectoryAsync(this ISftpDirectory directory, string path, CancellationToken cancellationToken)

Parameters

directory ISftpDirectory

The working directory.

path string

The directory path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

CreateNewFileAsync(ISftpDirectory, string, FileAccess, CancellationToken)

Creates a new file. Fails if it already exists.

public static ValueTask<SftpFile> CreateNewFileAsync(this ISftpDirectory directory, string path, FileAccess access, CancellationToken cancellationToken = default)

Parameters

directory ISftpDirectory

The working directory.

path string

The file path.

access FileAccess

The FileAccess mode.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<SftpFile>

SftpFile instance for the opened file.

DeleteDirectoryAsync(ISftpDirectory, string, CancellationToken)

Deletes a directory. This does not fail when the directory does not exist.

public static ValueTask DeleteDirectoryAsync(this ISftpDirectory directory, string path, CancellationToken cancellationToken)

Parameters

directory ISftpDirectory

The working directory.

path string

The directory path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

DownloadDirectoryEntriesAsync(ISftpDirectory, string, string, CancellationToken)

Downloads directory entries.

public static ValueTask DownloadDirectoryEntriesAsync(this ISftpDirectory directory, string remoteDirPath, string localDirPath, CancellationToken cancellationToken = default)

Parameters

directory ISftpDirectory

The working directory.

remoteDirPath string

The remote directory path.

localDirPath string

The local directory path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

DownloadFileAsync(ISftpDirectory, string, string, CancellationToken)

Downloads a file.

public static ValueTask DownloadFileAsync(this ISftpDirectory directory, string remoteFilePath, string localFilePath, CancellationToken cancellationToken)

Parameters

directory ISftpDirectory

The working directory.

remoteFilePath string

The remote file path.

localFilePath string

The local file path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

GetAttributesAsync(ISftpDirectory, string, bool, CancellationToken)

Gets file or directory attributes.

public static ValueTask<FileEntryAttributes?> GetAttributesAsync(this ISftpDirectory directory, string path, bool followLinks = true, CancellationToken cancellationToken = default)

Parameters

directory ISftpDirectory

The working directory.

path string

The file or directory path.

followLinks bool

Whether to follow symbolic links.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<FileEntryAttributes>

The FileEntryAttributes, or null if not found.

Remarks

To retrieve extended attributes, use the overload that accepts a filter argument.

GetAttributesAsync(ISftpDirectory, string, CancellationToken)

Gets file or directory attributes.

public static ValueTask<FileEntryAttributes?> GetAttributesAsync(this ISftpDirectory directory, string path, CancellationToken cancellationToken)

Parameters

directory ISftpDirectory

The working directory.

path string

The file or directory path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<FileEntryAttributes>

The FileEntryAttributes, or null if not found.

Remarks

To retrieve extended attributes, use the overload that accepts a filter argument.

GetDirectoryEntriesAsync(ISftpDirectory, string, EnumerationOptions?)

Enumerates directory entries asynchronously.

public static IAsyncEnumerable<(string Path, FileEntryAttributes Attributes)> GetDirectoryEntriesAsync(this ISftpDirectory directory, string path, EnumerationOptions? options = null)

Parameters

directory ISftpDirectory

The working directory.

path string

The directory path to enumerate.

options EnumerationOptions

EnumerationOptions for enumeration.

Returns

IAsyncEnumerable<(string Path, FileEntryAttributes Attributes)>

An async enumerable of path and FileEntryAttributes tuples.

OpenFileAsync(ISftpDirectory, string, FileAccess, CancellationToken)

Opens an existing file.

public static ValueTask<SftpFile?> OpenFileAsync(this ISftpDirectory directory, string path, FileAccess access, CancellationToken cancellationToken = default)

Parameters

directory ISftpDirectory

The working directory.

path string

The file path.

access FileAccess

The FileAccess mode.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<SftpFile>

An SftpFile for the opened file, or null if it doesn't exist.

OpenOrCreateFileAsync(ISftpDirectory, string, FileAccess, CancellationToken)

Opens an existing file or creates it when it does not yet exist.

public static ValueTask<SftpFile> OpenOrCreateFileAsync(this ISftpDirectory directory, string path, FileAccess access, CancellationToken cancellationToken = default)

Parameters

directory ISftpDirectory

The working directory.

path string

The file path.

access FileAccess

The FileAccess mode.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<SftpFile>

SftpFile instance for the opened file.

UploadDirectoryEntriesAsync(ISftpDirectory, string, string, CancellationToken)

Uploads directory entries.

public static ValueTask UploadDirectoryEntriesAsync(this ISftpDirectory directory, string localDirPath, string remoteDirPath, CancellationToken cancellationToken = default)

Parameters

directory ISftpDirectory

The working directory.

localDirPath string

The local directory path.

remoteDirPath string

The remote directory path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

UploadFileAsync(ISftpDirectory, Stream, string, CancellationToken)

Uploads a file from a Stream.

public static ValueTask UploadFileAsync(this ISftpDirectory directory, Stream source, string remoteFilePath, CancellationToken cancellationToken)

Parameters

directory ISftpDirectory

The working directory.

source Stream

The source Stream.

remoteFilePath string

The remote file path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

UploadFileAsync(ISftpDirectory, string, string, CancellationToken)

Uploads a file.

public static ValueTask UploadFileAsync(this ISftpDirectory directory, string localFilePath, string remoteFilePath, CancellationToken cancellationToken)

Parameters

directory ISftpDirectory

The working directory.

localFilePath string

The local file path.

remoteFilePath string

The remote file path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask