Skip to content

Commit 330e933

Browse files
authored
Truncate local file in ScpClient.Download (#1729)
Similar to #1686 but for the local side of SCP: opening the file should use Create not OpenWrite. closes #648
1 parent 3910658 commit 330e933

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
@@ -824,7 +824,7 @@ private void InternalDownload(IChannelSession channel, Stream input, FileSystemI
824824
fileInfo = new FileInfo(Path.Combine(currentDirectoryFullName, fileName));
825825
}
826826

827-
using (var output = fileInfo.OpenWrite())
827+
using (var output = fileInfo.Open(FileMode.Create, FileAccess.Write))
828828
{
829829
InternalDownload(channel, input, output, fileName, length);
830830
}

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)