Skip to content

Commit 659cd54

Browse files
committed
Truncate local file in ScpClient.Download
Similar to sshnet#1686 but for the local side of SCP: opening the file should use Create not OpenWrite. closes sshnet#648
1 parent e5ad82c commit 659cd54

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Renci.SshNet/ScpClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ private void InternalDownload(IChannelSession channel, Stream input, FileSystemI
831831
fileInfo = new FileInfo(Path.Combine(currentDirectoryFullName, fileName));
832832
}
833833

834-
using (var output = fileInfo.OpenWrite())
834+
using (var output = fileInfo.Open(FileMode.Create, FileAccess.Write))
835835
{
836836
InternalDownload(channel, input, output, fileName, length);
837837
}

test/Renci.SshNet.IntegrationTests/ScpTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,8 @@ public void Scp_Download_FileInfo_ExistingFile(IRemotePathTransformation remoteP
679679
}
680680
}
681681

682-
var fileInfo = new FileInfo(Path.GetTempFileName());
682+
// Create a local file larger than the remote file in order to test truncation.
683+
var fileInfo = new FileInfo(CreateTempFile(size + 64));
683684

684685
try
685686
{

0 commit comments

Comments
 (0)