No exception when overwritting files on SSH site
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 4.4k
- Fork
- 993
- Merge medio
- 9g 21h
- PR unite (30g)
- 1
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Iniziare in src/Renci.SshNet/SftpClient.cs, nei pressi della documentazione collegata di BeginUploadFile, e seguire il flusso attraverso EndUploadFile, riproducendo l’esempio con due upload e canOverride impostato su false. Confrontare il comportamento osservato con il contratto documentato di SshException e stabilire una copertura di regressione che mostri il risultato previsto quando la destinazione esiste già.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- networking
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100