sshnet / sshnet/SSH.NET

Renci.SshNet.Common.SshException: Failure. exception

Offen
#582 8 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C#
Sterne
4.4k
Forks
993
Ø Merge
9 T. 21 Std.
Gemergte PRs (30 T.)
1

Beschreibung

Hello,

I have been using the Renci SSH.NET(2016.1.0.0) NuGet package in my web api code, to transfer files from server to a remote SFTP server. This has been working very well for me. The issue I am facing is that I am getting the error marked below. My .NET framework version is 4.6

An exception has been caught during the file upload..:Renci.SshNet.Common.SshException: Failure.
at Renci.SshNet.Sftp.SftpSession.RequestOpen(String path, Flags flags, Boolean nullOnError)
at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action1 uploadCallback) at Renci.SshNet.SftpClient.UploadFile(Stream input, String path, Action1 uploadCallback)
at BASF.TAR.RMSService.Controllers.AttachmentController.Get(String sourcepaths, String destinationpath) in d:\Projects\TAR\Samples\BASF.TAR.RMSService\BASF.TAR.RMSService\Controllers\AttachmentController.cs:line 47

I am using the code in my controller as below, its a simple function that takes a source path which is pipe seperated strings and a destination path which is the path on the remote FTP server. The client opens the connection to the server and then in a loop manner each file is uploaded to the remote server and the log is printed.

Please can you let me know why this error is occuring sometimes, any help would be greatly appreciated

public IHttpActionResult Get([FromUri]string sourcepaths, string destinationpath)
        {
            var fileInfo = new List<string>();

            log.Info("Entering the Put() method of the AttachmentController class..");
            try
            {
                using (SftpClient sftp = new SftpClient(ConfigurationManager.AppSettings["SFTP"].ToString(), Convert.ToInt32(ConfigurationManager.AppSettings["Port"].ToString()), ConfigurationManager.AppSettings["UserId"].ToString(), ConfigurationManager.AppSettings["Password"].ToString()))
                {
                    try
                    {
                        if (string.IsNullOrEmpty(sourcepaths) && string.IsNullOrEmpty(destinationpath)) return Ok();

                        var filePaths = sourcepaths.Split('|');
                        sftp.Connect();
                        log.InfoFormat("Connected to SFTP server:{0}..", ConfigurationManager.AppSettings["SFTP"].ToString());
                        
                        log.InfoFormat("Original destination path:{0}", destinationpath);
                        log.InfoFormat("Upload path in the sftp location:{0}", OriginalAttPathToFileSharePath(destinationpath.ToLower()));

                        log.Info("Uploading file...");

                        sftp.ChangeDirectory(OriginalAttPathToFileSharePath(destinationpath.ToLower()));
                        log.InfoFormat("Original destination path:{0}", destinationpath);
                        log.InfoFormat("Upload path in the sftp location:{0}", OriginalAttPathToFileSharePath(destinationpath.ToLower()));
                        foreach (var file in filePaths)
                        {
                            log.InfoFormat("File to be uploaded:{0}", file);
                            using (var stream = new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                            {
                                sftp.UploadFile(stream, Path.GetFileName(file), (o) =>
                                {
                                    Console.WriteLine(o);
                                });
                            }
                        }
                        log.Info("File uploaded to server...");
                        sftp.Disconnect();
                    }
                    catch (Exception e)
                    {
                        log.ErrorFormat("An exception has been caught during the file upload..:{0}", e);
                    }
                }
            }
            catch (Exception exp)
            {
                log.Error("Error occured in the Put() method of the AttachmentController class..", exp);
            }
            log.Info("Exiting the Put() method of the AttachmentController class..");
            return Ok();
        }

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit dem im Bericht gezeigten Aufruf SftpClient.UploadFile und dem Stack-Eintrag SftpSession.RequestOpen und untersuchen Sie anschließend den ChangeDirectory- und den wiederholten Upload-Ablauf des Controllers. Reproduzieren Sie den intermittierenden Fehler mit den angegebenen Details zu .NET Framework 4.6 und SSH.NET 2016.1.0.0 sowie gleichwertigen Pfaden. Als abgeschlossen gilt die Aufgabe, wenn Sie entweder eine reproduzierbare Ursache oder die fehlenden Server-/Pfadinformationen identifiziert haben, die für die Fortsetzung benötigt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.