SSH.NET icon indicating copy to clipboard operation
SSH.NET copied to clipboard

No exception when overwritting files on SSH site

Open PaitoAnderson opened this issue 5 years ago • 1 comments

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.

PaitoAnderson avatar Apr 10 '19 15:04 PaitoAnderson

I have the same problem when uploading to a server that identifies itself as "SSH-2.0-CerberusFTPServer_12.0".

Did you ever find a fix for your problem?

phlexss avatar Sep 21 '23 09:09 phlexss