mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-10-29 15:11:12 +08:00
Added GetAttributesAsync to SftpClient (#1648)
* Added GetAttributesAsync to SftpClient * Adding integration tests + unit test * Address warnings in test classes. --------- Co-authored-by: William Decker <william.decker@syndigo.com>
This commit is contained in:
co-authored by
William Decker
parent
03e28219ba
commit
9cf282731a
@@ -700,6 +700,21 @@ namespace Renci.SshNet
|
||||
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
||||
SftpFileAttributes GetAttributes(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="SftpFileAttributes"/> of the file on the path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the file.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
|
||||
/// <returns>
|
||||
/// A <see cref="Task{SftpFileAttributes}"/> that represents the attribute retrieval operation.
|
||||
/// The task result contains the <see cref="SftpFileAttributes"/> of the file on the path.
|
||||
/// </returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
||||
/// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
||||
Task<SftpFileAttributes> GetAttributesAsync(string path, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the date and time the specified file or directory was last accessed.
|
||||
/// </summary>
|
||||
|
||||
@@ -2094,6 +2094,33 @@ namespace Renci.SshNet
|
||||
return _sftpSession.RequestLStat(fullPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="SftpFileAttributes"/> of the file on the path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the file.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
|
||||
/// <returns>
|
||||
/// A <see cref="Task{SftpFileAttributes}"/> that represents the attribute retrieval operation.
|
||||
/// The task result contains the <see cref="SftpFileAttributes"/> of the file on the path.
|
||||
/// </returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
||||
/// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
|
||||
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
||||
public async Task<SftpFileAttributes> GetAttributesAsync(string path, CancellationToken cancellationToken)
|
||||
{
|
||||
CheckDisposed();
|
||||
|
||||
if (_sftpSession is null)
|
||||
{
|
||||
throw new SshConnectionException("Client not connected.");
|
||||
}
|
||||
|
||||
var fullPath = await _sftpSession.GetCanonicalPathAsync(path, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return await _sftpSession.RequestLStatAsync(fullPath, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the specified <see cref="SftpFileAttributes"/> of the file on the specified path.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user