No exception when overwritting files on SSH site
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.4k
- Forks
- 993
- Avg merge
- 9d 21h
- Merged PRs (30d)
- 1
Description
Hello,
I'm having an issue when uploading detecting if a file exists and will be overwritten or not, based on this comment I assumed an exception would be thrown, but it doesn't look like it.
/// When <paramref name="path"/> refers to an existing file, set <paramref name="canOverride"/> to <c>true</c> to overwrite and truncate that file.
/// If <paramref name="canOverride"/> is <c>false</c>, the upload will fail and <see cref="EndUploadFile(IAsyncResult)"/> will throw an
/// <see cref="SshException"/>.
https://github.com/sshnet/SSH.NET/blob/master/src/Renci.SshNet/SftpClient.cs#L906
Sample code:
using Renci.SshNet;
using Renci.SshNet.Sftp;
using System;
using System.IO;
namespace UploadTesting
{
class Program
{
static void Main(string[] args)
{
var file1 = File.ReadAllBytes(@"logo.jpg");
var file2 = File.ReadAllBytes(@"truck.jpg");
using (var client = new SftpClient("XXX", "XXX", "XXX"))
{
client.Connect();
var stream1 = new MemoryStream(file1);
var stream2 = new MemoryStream(file1);
var result1 = client.BeginUploadFile(stream1, "test.jpg", false, (e) => {}, stream1);
while (!result1.IsCompleted) { }
client.EndUploadFile(result1);
var result2 = client.BeginUploadFile(stream2, "test.jpg", false, (e) => {}, stream2);
while (!result2.IsCompleted) { }
client.EndUploadFile(result2);
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
When I run this code only the logo.jpg is uploaded, an no exception is thrown.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/Renci.SshNet/SftpClient.cs around the linked BeginUploadFile documentation and trace through EndUploadFile, reproducing the two-upload sample with canOverride set to false. Compare the observed behavior with the documented SshException contract and establish regression coverage showing the expected result when the destination already exists.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100