Table of Contents

Interface ISftpDirectory

Namespace
Tmds.Ssh
Assembly
Tmds.Ssh.dll

Interface for SFTP directory operations.

public interface ISftpDirectory
Extension Methods

Properties

Path

Gets the directory path.

string Path { get; }

Property Value

string

Methods

CopyFileAsync(string, string, bool, CancellationToken)

Copies a file.

ValueTask CopyFileAsync(string sourcePath, string destinationPath, bool overwrite = false, CancellationToken cancellationToken = default)

Parameters

sourcePath string

The source file path.

destinationPath string

The destination file path.

overwrite bool

Whether to overwrite an existing file.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

CreateDirectoryAsync(string, bool, UnixFilePermissions, CancellationToken)

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

ValueTask CreateDirectoryAsync(string path, bool createParents = false, UnixFilePermissions permissions = UnixFilePermissions.OtherExecute | UnixFilePermissions.OtherWrite | UnixFilePermissions.OtherRead | UnixFilePermissions.GroupExecute | UnixFilePermissions.GroupWrite | UnixFilePermissions.GroupRead | UnixFilePermissions.UserExecute | UnixFilePermissions.UserWrite | UnixFilePermissions.UserRead, CancellationToken cancellationToken = default)

Parameters

path string

The directory path.

createParents bool

Whether to create parent directories.

permissions UnixFilePermissions

UnixFilePermissions used when a new directory is created.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

CreateNewDirectoryAsync(string, bool, UnixFilePermissions, CancellationToken)

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

ValueTask CreateNewDirectoryAsync(string path, bool createParents = false, UnixFilePermissions permissions = UnixFilePermissions.OtherExecute | UnixFilePermissions.OtherWrite | UnixFilePermissions.OtherRead | UnixFilePermissions.GroupExecute | UnixFilePermissions.GroupWrite | UnixFilePermissions.GroupRead | UnixFilePermissions.UserExecute | UnixFilePermissions.UserWrite | UnixFilePermissions.UserRead, CancellationToken cancellationToken = default)

Parameters

path string

The directory path.

createParents bool

Whether to create parent directories.

permissions UnixFilePermissions

UnixFilePermissions for the new directory.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

CreateNewFileAsync(string, FileAccess, FileOpenOptions?, CancellationToken)

Creates a new file. Fails if it already exists.

ValueTask<SftpFile> CreateNewFileAsync(string path, FileAccess access, FileOpenOptions? options, CancellationToken cancellationToken = default)

Parameters

path string

The file path.

access FileAccess

The FileAccess mode.

options FileOpenOptions

FileOpenOptions for creating the file.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<SftpFile>

SftpFile instance for the opened file.

CreateSymbolicLinkAsync(string, string, CancellationToken)

Creates a symbolic link.

ValueTask CreateSymbolicLinkAsync(string linkPath, string targetPath, CancellationToken cancellationToken = default)

Parameters

linkPath string

The symbolic link path to create.

targetPath string

The target path the link points to.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

DeleteDirectoryAsync(string, bool, CancellationToken)

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

ValueTask DeleteDirectoryAsync(string path, bool recursive = false, CancellationToken cancellationToken = default)

Parameters

path string

The directory path.

recursive bool

Whether to delete directories recursively.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

DeleteFileAsync(string, CancellationToken)

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

ValueTask DeleteFileAsync(string path, CancellationToken cancellationToken = default)

Parameters

path string

The file path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

DownloadDirectoryEntriesAsync(string, string, DownloadEntriesOptions?, CancellationToken)

Downloads directory entries.

ValueTask DownloadDirectoryEntriesAsync(string remoteDirPath, string localDirPath, DownloadEntriesOptions? options, CancellationToken cancellationToken = default)

Parameters

remoteDirPath string

The remote directory path.

localDirPath string

The local directory path.

options DownloadEntriesOptions

DownloadEntriesOptions for the download operation.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

DownloadFileAsync(string, Stream, CancellationToken)

Downloads a file to a Stream.

ValueTask DownloadFileAsync(string remoteFilePath, Stream destination, CancellationToken cancellationToken = default)

Parameters

remoteFilePath string

The remote file path.

destination Stream

The destination Stream.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

DownloadFileAsync(string, string, bool, CancellationToken)

Downloads a file.

ValueTask DownloadFileAsync(string remoteFilePath, string localFilePath, bool overwrite = false, CancellationToken cancellationToken = default)

Parameters

remoteFilePath string

The remote file path.

localFilePath string

The local file path.

overwrite bool

Whether to overwrite an existing file.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

GetAttributesAsync(string, bool, string[]?, CancellationToken)

Gets file or directory attributes.

ValueTask<FileEntryAttributes?> GetAttributesAsync(string path, bool followLinks, string[]? filter, CancellationToken cancellationToken = default)

Parameters

path string

The file or directory path.

followLinks bool

Whether to follow symbolic links.

filter string[]

Extended attributes to include. Set to null to include all.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<FileEntryAttributes>

The FileEntryAttributes, or null if not found.

GetDirectory(string)

Gets an SftpDirectory for the specified path.

ISftpDirectory GetDirectory(string path)

Parameters

path string

The directory path.

Returns

ISftpDirectory

An ISftpDirectory for the specified path.

GetDirectoryEntriesAsync<T>(string, SftpFileEntryTransform<T>, EnumerationOptions?)

Enumerates directory entries asynchronously.

IAsyncEnumerable<T> GetDirectoryEntriesAsync<T>(string path, SftpFileEntryTransform<T> transform, EnumerationOptions? options = null)

Parameters

path string

The directory path to enumerate.

transform SftpFileEntryTransform<T>

SftpFileEntryTransform<T> function for each entry.

options EnumerationOptions

EnumerationOptions for enumeration.

Returns

IAsyncEnumerable<T>

An async enumerable of transformed entries.

Type Parameters

T

Result type to transform entries to.

GetLinkTargetAsync(string, CancellationToken)

Gets the target of a symbolic link.

ValueTask<string> GetLinkTargetAsync(string linkPath, CancellationToken cancellationToken = default)

Parameters

linkPath string

The symbolic link path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<string>

The target path.

GetRealPathAsync(string, CancellationToken)

Resolves a path to its canonical absolute path.

ValueTask<string> GetRealPathAsync(string path, CancellationToken cancellationToken = default)

Parameters

path string

The path to resolve.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<string>

The canonical absolute path.

OpenFileAsync(string, FileAccess, FileOpenOptions?, CancellationToken)

Opens an existing file.

ValueTask<SftpFile?> OpenFileAsync(string path, FileAccess access, FileOpenOptions? options, CancellationToken cancellationToken = default)

Parameters

path string

The file path.

access FileAccess

The FileAccess mode.

options FileOpenOptions

FileOpenOptions for opening the file.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<SftpFile>

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

OpenOrCreateFileAsync(string, FileAccess, FileOpenOptions?, CancellationToken)

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

ValueTask<SftpFile> OpenOrCreateFileAsync(string path, FileAccess access, FileOpenOptions? options, CancellationToken cancellationToken = default)

Parameters

path string

The file path.

access FileAccess

The FileAccess mode.

options FileOpenOptions

FileOpenOptions for opening the file.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask<SftpFile>

SftpFile instance for the opened file.

RenameAsync(string, string, CancellationToken)

Renames or moves a file or directory.

ValueTask RenameAsync(string oldPath, string newPath, CancellationToken cancellationToken = default)

Parameters

oldPath string

The current path.

newPath string

The new path.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

SetAttributesAsync(string, UnixFilePermissions?, (DateTimeOffset LastAccess, DateTimeOffset LastWrite)?, long?, (int Uid, int Gid)?, IEnumerable<KeyValuePair<string, Memory<byte>>>?, CancellationToken)

Sets file or directory attributes.

ValueTask SetAttributesAsync(string path, UnixFilePermissions? permissions = null, (DateTimeOffset LastAccess, DateTimeOffset LastWrite)? times = null, long? length = null, (int Uid, int Gid)? ids = null, IEnumerable<KeyValuePair<string, Memory<byte>>>? extendedAttributes = null, CancellationToken cancellationToken = default)

Parameters

path string

The file or directory path.

permissions UnixFilePermissions?

UnixFilePermissions to set.

times (DateTimeOffset LastAccess, DateTimeOffset LastWrite)?

Access and modification times to set.

length long?

File length to set (truncates or extends).

ids (int Uid, int Gid)?

User and group IDs to set.

extendedAttributes IEnumerable<KeyValuePair<string, Memory<byte>>>

Extended attributes to set.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

UploadDirectoryEntriesAsync(string, string, UploadEntriesOptions?, CancellationToken)

Uploads directory entries.

ValueTask UploadDirectoryEntriesAsync(string localDirPath, string remoteDirPath, UploadEntriesOptions? options, CancellationToken cancellationToken = default)

Parameters

localDirPath string

The local directory path.

remoteDirPath string

The remote directory path.

options UploadEntriesOptions

UploadEntriesOptions for the upload operation.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

UploadFileAsync(Stream, string, bool, UnixFilePermissions, CancellationToken)

Uploads a file from a Stream.

ValueTask UploadFileAsync(Stream source, string remoteFilePath, bool overwrite = false, UnixFilePermissions createPermissions = UnixFilePermissions.OtherWrite | UnixFilePermissions.OtherRead | UnixFilePermissions.GroupWrite | UnixFilePermissions.GroupRead | UnixFilePermissions.UserWrite | UnixFilePermissions.UserRead, CancellationToken cancellationToken = default)

Parameters

source Stream

The source Stream.

remoteFilePath string

The remote file path.

overwrite bool

Whether to overwrite an existing file.

createPermissions UnixFilePermissions

UnixFilePermissions when a new file is created.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask

UploadFileAsync(string, string, bool, UnixFilePermissions?, CancellationToken)

Uploads a file.

ValueTask UploadFileAsync(string localFilePath, string remoteFilePath, bool overwrite = false, UnixFilePermissions? createPermissions = null, CancellationToken cancellationToken = default)

Parameters

localFilePath string

The local file path.

remoteFilePath string

The remote file path.

overwrite bool

Whether to overwrite an existing file.

createPermissions UnixFilePermissions?

UnixFilePermissions when a new file is created.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

ValueTask