Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/Renci.SshNet/ISftpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public interface ISftpClient : IBaseClient
/// </summary>
/// <param name="path">The path and name of the file to create.</param>
/// <returns>
/// A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path.
/// A <see cref="Stream"/> that provides read/write access to the file specified in path.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
Expand All @@ -398,15 +398,15 @@ public interface ISftpClient : IBaseClient
/// <remarks>
/// If the target file already exists, it is first truncated to zero bytes.
/// </remarks>
SftpFileStream Create(string path);
Stream Create(string path);

/// <summary>
/// Creates or overwrites the specified file.
/// </summary>
/// <param name="path">The path and name of the file to create.</param>
/// <param name="bufferSize">The maximum number of bytes buffered for reads and writes to the file.</param>
/// <returns>
/// A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path.
/// A <see cref="Stream"/> that provides read/write access to the file specified in path.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
Expand All @@ -415,7 +415,7 @@ public interface ISftpClient : IBaseClient
/// <remarks>
/// If the target file already exists, it is first truncated to zero bytes.
/// </remarks>
SftpFileStream Create(string path, int bufferSize);
Stream Create(string path, int bufferSize);

/// <summary>
/// Creates remote directory specified by path.
Expand Down Expand Up @@ -817,59 +817,59 @@ public interface ISftpClient : IBaseClient
IAsyncEnumerable<ISftpFile> ListDirectoryAsync(string path, CancellationToken cancellationToken);

/// <summary>
/// Opens a <see cref="SftpFileStream"/> on the specified path with read/write access.
/// Opens a <see cref="Stream"/> on the specified path with read/write access.
/// </summary>
/// <param name="path">The file to open.</param>
/// <param name="mode">A <see cref="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.</param>
/// <returns>
/// An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and read/write access.
/// An unshared <see cref="Stream"/> that provides access to the specified file, with the specified mode and read/write access.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
SftpFileStream Open(string path, FileMode mode);
Stream Open(string path, FileMode mode);

/// <summary>
/// Opens a <see cref="SftpFileStream"/> on the specified path, with the specified mode and access.
/// Opens a <see cref="Stream"/> on the specified path, with the specified mode and access.
/// </summary>
/// <param name="path">The file to open.</param>
/// <param name="mode">A <see cref="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.</param>
/// <param name="access">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file.</param>
/// <returns>
/// An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.
/// An unshared <see cref="Stream"/> that provides access to the specified file, with the specified mode and access.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
SftpFileStream Open(string path, FileMode mode, FileAccess access);
Stream Open(string path, FileMode mode, FileAccess access);

/// <summary>
/// Asynchronously opens a <see cref="SftpFileStream"/> on the specified path, with the specified mode and access.
/// Asynchronously opens a <see cref="Stream"/> on the specified path, with the specified mode and access.
/// </summary>
/// <param name="path">The file to open.</param>
/// <param name="mode">A <see cref="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.</param>
/// <param name="access">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
/// <returns>
/// A <see cref="Task{SftpFileStream}"/> that represents the asynchronous open operation.
/// The task result contains the <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.
/// A <see cref="Task{Stream}"/> that represents the asynchronous open operation.
/// The task result contains the <see cref="Stream"/> that provides access to the specified file, with the specified mode and access.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
Task<SftpFileStream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken);
Task<Stream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken);

/// <summary>
/// Opens an existing file for reading.
/// </summary>
/// <param name="path">The file to be opened for reading.</param>
/// <returns>
/// A read-only <see cref="SftpFileStream"/> on the specified path.
/// A read-only <see cref="Stream"/> on the specified path.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
SftpFileStream OpenRead(string path);
Stream OpenRead(string path);

/// <summary>
/// Opens an existing UTF-8 encoded text file for reading.
Expand All @@ -888,15 +888,15 @@ public interface ISftpClient : IBaseClient
/// </summary>
/// <param name="path">The file to be opened for writing.</param>
/// <returns>
/// An unshared <see cref="SftpFileStream"/> object on the specified path with <see cref="FileAccess.Write"/> access.
/// An unshared <see cref="Stream"/> object on the specified path with <see cref="FileAccess.Write"/> access.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
/// <remarks>
/// If the file does not exist, it is created.
/// </remarks>
SftpFileStream OpenWrite(string path);
Stream OpenWrite(string path);

/// <summary>
/// Opens a binary file, reads the contents of the file into a byte array, and closes the file.
Expand Down
38 changes: 19 additions & 19 deletions src/Renci.SshNet/SftpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ public StreamWriter AppendText(string path, Encoding encoding)
/// </summary>
/// <param name="path">The path and name of the file to create.</param>
/// <returns>
/// A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path.
/// A <see cref="Stream"/> that provides read/write access to the file specified in path.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
Expand All @@ -1466,7 +1466,7 @@ public StreamWriter AppendText(string path, Encoding encoding)
/// <remarks>
/// If the target file already exists, it is first truncated to zero bytes.
/// </remarks>
public SftpFileStream Create(string path)
public Stream Create(string path)
{
return Create(path, (int)_bufferSize);
}
Expand All @@ -1477,7 +1477,7 @@ public SftpFileStream Create(string path)
/// <param name="path">The path and name of the file to create.</param>
/// <param name="bufferSize">The maximum number of bytes buffered for reads and writes to the file.</param>
/// <returns>
/// A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path.
/// A <see cref="Stream"/> that provides read/write access to the file specified in path.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
Expand All @@ -1486,7 +1486,7 @@ public SftpFileStream Create(string path)
/// <remarks>
/// If the target file already exists, it is first truncated to zero bytes.
/// </remarks>
public SftpFileStream Create(string path, int bufferSize)
public Stream Create(string path, int bufferSize)
{
CheckDisposed();

Expand Down Expand Up @@ -1597,72 +1597,72 @@ public DateTime GetLastWriteTimeUtc(string path)
}

/// <summary>
/// Opens a <see cref="SftpFileStream"/> on the specified path with read/write access.
/// Opens a <see cref="Stream"/> on the specified path with read/write access.
/// </summary>
/// <param name="path">The file to open.</param>
/// <param name="mode">A <see cref="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.</param>
/// <returns>
/// An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and read/write access.
/// An unshared <see cref="Stream"/> that provides access to the specified file, with the specified mode and read/write access.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
public SftpFileStream Open(string path, FileMode mode)
public Stream Open(string path, FileMode mode)
{
return Open(path, mode, FileAccess.ReadWrite);
}

/// <summary>
/// Opens a <see cref="SftpFileStream"/> on the specified path, with the specified mode and access.
/// Opens a <see cref="Stream"/> on the specified path, with the specified mode and access.
/// </summary>
/// <param name="path">The file to open.</param>
/// <param name="mode">A <see cref="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.</param>
/// <param name="access">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file.</param>
/// <returns>
/// An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.
/// An unshared <see cref="Stream"/> that provides access to the specified file, with the specified mode and access.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
public SftpFileStream Open(string path, FileMode mode, FileAccess access)
public Stream Open(string path, FileMode mode, FileAccess access)
{
CheckDisposed();

return SftpFileStream.Open(_sftpSession, path, mode, access, (int)_bufferSize);
}

/// <summary>
/// Asynchronously opens a <see cref="SftpFileStream"/> on the specified path, with the specified mode and access.
/// Asynchronously opens a <see cref="Stream"/> on the specified path, with the specified mode and access.
/// </summary>
/// <param name="path">The file to open.</param>
/// <param name="mode">A <see cref="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.</param>
/// <param name="access">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
/// <returns>
/// A <see cref="Task{SftpFileStream}"/> that represents the asynchronous open operation.
/// The task result contains the <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.
/// A <see cref="Task{Stream}"/> that represents the asynchronous open operation.
/// The task result contains the <see cref="Stream"/> that provides access to the specified file, with the specified mode and access.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
public Task<SftpFileStream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken)
public async Task<Stream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken)
{
CheckDisposed();

return SftpFileStream.OpenAsync(_sftpSession, path, mode, access, (int)_bufferSize, cancellationToken);
return await SftpFileStream.OpenAsync(_sftpSession, path, mode, access, (int)_bufferSize, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Opens an existing file for reading.
/// </summary>
/// <param name="path">The file to be opened for reading.</param>
/// <returns>
/// A read-only <see cref="SftpFileStream"/> on the specified path.
/// A read-only <see cref="Stream"/> on the specified path.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
public SftpFileStream OpenRead(string path)
public Stream OpenRead(string path)
{
return Open(path, FileMode.Open, FileAccess.Read);
}
Expand All @@ -1687,15 +1687,15 @@ public StreamReader OpenText(string path)
/// </summary>
/// <param name="path">The file to be opened for writing.</param>
/// <returns>
/// An unshared <see cref="SftpFileStream"/> object on the specified path with <see cref="FileAccess.Write"/> access.
/// An unshared <see cref="Stream"/> object on the specified path with <see cref="FileAccess.Write"/> access.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
/// <remarks>
/// If the file does not exist, it is created.
/// </remarks>
public SftpFileStream OpenWrite(string path)
public Stream OpenWrite(string path)
{
return Open(path, FileMode.OpenOrCreate, FileAccess.Write);
}
Expand Down
10 changes: 5 additions & 5 deletions test/Renci.SshNet.IntegrationTests/SftpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void Sftp_Create_DirectoryDoesNotExist()
client.DeleteFile(remoteFile);
}

SftpFileStream fs = null;
Stream fs = null;

try
{
Expand Down Expand Up @@ -4000,8 +4000,8 @@ public void Sftp_SftpFileStream_ReadAndWriteAsyncMemory()
#endif

private void TestReadAndWrite(
Func<SftpFileStream, byte[], int, int, int> read,
Action<SftpFileStream, byte[], int, int> write)
Func<Stream, byte[], int, int, int> read,
Action<Stream, byte[], int, int> write)
{
using (var client = new SftpClient(_connectionInfoFactory.Create()))
{
Expand Down Expand Up @@ -4107,14 +4107,14 @@ private void TestReadAndWrite(
}
}

int ReadByte(SftpFileStream s)
int ReadByte(Stream s)
{
var buffer = new byte[1];
var bytesRead = read(s, buffer, 0, 1);
return bytesRead == 0 ? -1 : buffer[0];
}

void WriteByte(SftpFileStream s, byte b)
void WriteByte(Stream s, byte b)
{
write(s, [b], 0, 1);
}
Expand Down
Loading