Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
remove notifyOnEmptyFile Flag
  • Loading branch information
thegame4craft committed Jun 19, 2025
commit 153419793472f2d6d45d329035d1464bef2bbf88
27 changes: 11 additions & 16 deletions src/Renci.SshNet/ScpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,12 @@ internal ScpClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo, IServ
/// </summary>
/// <param name="source">The <see cref="Stream"/> to upload.</param>
/// <param name="path">A relative or absolute path for the remote file.</param>
/// <param name="notifyOnEmptyFile">Should the <see cref="Uploading"/> event be raised when the file is empty?</param>
/// <exception cref="ArgumentNullException"><paramref name="path" /> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length <see cref="string"/>.</exception>
/// <exception cref="ScpException">A directory with the specified path exists on the remote host.</exception>
/// <exception cref="SshException">The secure copy execution request was rejected by the server.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
public void Upload(Stream source, string path, bool notifyOnEmptyFile=false)
public void Upload(Stream source, string path)
{
if (Session is null)
{
Expand All @@ -272,7 +271,7 @@ public void Upload(Stream source, string path, bool notifyOnEmptyFile=false)
CheckReturnCode(input);

UploadFileModeAndName(channel, input, source.Length, posixPath.File);
UploadFileContent(channel, input, source, posixPath.File, notifyOnEmptyFile);
UploadFileContent(channel, input, source, posixPath.File);
}
}

Expand All @@ -281,14 +280,13 @@ public void Upload(Stream source, string path, bool notifyOnEmptyFile=false)
/// </summary>
/// <param name="fileInfo">The file system info.</param>
/// <param name="path">A relative or absolute path for the remote file.</param>
/// <param name="notifyOnEmptyFile">Should the <see cref="Uploading"/> event be raised when the file is empty?</param>
/// <exception cref="ArgumentNullException"><paramref name="fileInfo" /> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="path" /> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length <see cref="string"/>.</exception>
/// <exception cref="ScpException">A directory with the specified path exists on the remote host.</exception>
/// <exception cref="SshException">The secure copy execution request was rejected by the server.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
public void Upload(FileInfo fileInfo, string path, bool notifyOnEmptyFile=false)
public void Upload(FileInfo fileInfo, string path)
{
ThrowHelper.ThrowIfNull(fileInfo);

Expand Down Expand Up @@ -319,7 +317,7 @@ public void Upload(FileInfo fileInfo, string path, bool notifyOnEmptyFile=false)
{
UploadTimes(channel, input, fileInfo);
UploadFileModeAndName(channel, input, source.Length, posixPath.File);
UploadFileContent(channel, input, source, fileInfo.Name, notifyOnEmptyFile);
UploadFileContent(channel, input, source, fileInfo.Name);
}
}
}
Expand All @@ -329,14 +327,13 @@ public void Upload(FileInfo fileInfo, string path, bool notifyOnEmptyFile=false)
/// </summary>
/// <param name="directoryInfo">The directory info.</param>
/// <param name="path">A relative or absolute path for the remote directory.</param>
/// <param name="notifyOnEmptyFile">Should the <see cref="Uploading"/> event be raised when the file is empty?</param>
/// <exception cref="ArgumentNullException"><paramref name="directoryInfo"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length string.</exception>
/// <exception cref="ScpException"><paramref name="path"/> does not exist on the remote host, is not a directory or the user does not have the required permission.</exception>
/// <exception cref="SshException">The secure copy execution request was rejected by the server.</exception>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
public void Upload(DirectoryInfo directoryInfo, string path, bool notifyOnEmptyFile=false)
public void Upload(DirectoryInfo directoryInfo, string path)
{
ThrowHelper.ThrowIfNull(directoryInfo);
ThrowHelper.ThrowIfNullOrEmpty(path);
Expand Down Expand Up @@ -365,7 +362,7 @@ public void Upload(DirectoryInfo directoryInfo, string path, bool notifyOnEmptyF

CheckReturnCode(input);

UploadDirectoryContent(channel, input, directoryInfo, notifyOnEmptyFile);
UploadDirectoryContent(channel, input, directoryInfo);
}
}

Expand Down Expand Up @@ -559,11 +556,10 @@ private void UploadFileModeAndName(IChannelSession channel, Stream input, long f
/// <param name="input">A <see cref="Stream"/> from which any feedback from the server can be read.</param>
/// <param name="source">The content to upload.</param>
/// <param name="remoteFileName">The name of the remote file, without path, to which the content is uploaded.</param>
/// <param name="notifyOnEmptyFile">Should the <see cref="Uploading"/> event be raised when the file is empty?</param>
/// <remarks>
/// <paramref name="remoteFileName"/> is only used for raising the <see cref="Uploading"/> event.
/// </remarks>
private void UploadFileContent(IChannelSession channel, Stream input, Stream source, string remoteFileName, bool notifyOnEmptyFile)
private void UploadFileContent(IChannelSession channel, Stream input, Stream source, string remoteFileName)
{
var totalLength = source.Length;
var buffer = new byte[BufferSize];
Expand All @@ -583,7 +579,7 @@ private void UploadFileContent(IChannelSession channel, Stream input, Stream sou
read = source.Read(buffer, 0, buffer.Length);
}

if (totalLength == 0 && totalRead == 0 && notifyOnEmptyFile)
if (totalLength == 0 && totalRead == 0)
{
RaiseUploadingEvent(remoteFileName, totalLength, totalRead);
}
Expand Down Expand Up @@ -696,8 +692,7 @@ private void UploadTimes(IChannelSession channel, Stream input, FileSystemInfo f
/// <param name="channel">The channel to perform the upload in.</param>
/// <param name="input">A <see cref="Stream"/> from which any feedback from the server can be read.</param>
/// <param name="directoryInfo">The directory to upload.</param>
/// <param name="notifyOnEmptyFile">Should the <see cref="Uploading"/> event be raised when the file is empty?</param>
private void UploadDirectoryContent(IChannelSession channel, Stream input, DirectoryInfo directoryInfo, bool notifyOnEmptyFile=false)
private void UploadDirectoryContent(IChannelSession channel, Stream input, DirectoryInfo directoryInfo)
{
// Upload files
var files = directoryInfo.GetFiles();
Expand All @@ -707,7 +702,7 @@ private void UploadDirectoryContent(IChannelSession channel, Stream input, Direc
{
UploadTimes(channel, input, file);
UploadFileModeAndName(channel, input, source.Length, file.Name);
UploadFileContent(channel, input, source, file.Name, notifyOnEmptyFile);
UploadFileContent(channel, input, source, file.Name);
}
}

Expand All @@ -717,7 +712,7 @@ private void UploadDirectoryContent(IChannelSession channel, Stream input, Direc
{
UploadTimes(channel, input, directory);
UploadDirectoryModeAndName(channel, input, directory.Name);
UploadDirectoryContent(channel, input, directory, notifyOnEmptyFile);
UploadDirectoryContent(channel, input, directory);
}

// Mark upload of current directory complete
Expand Down