<PackageReference Include="SSH.NET" Version="2025.1.0" />

SftpException

public class SftpException : SshException
The exception that is thrown when an error occurs in the SFTP layer.
using Renci.SshNet.Sftp; using System; using System.Runtime.CompilerServices; namespace Renci.SshNet.Common { [System.Runtime.CompilerServices.NullableContext(2)] [System.Runtime.CompilerServices.Nullable(0)] public class SftpException : SshException { public StatusCode StatusCode { get; } public SftpException(StatusCode statusCode) : this(statusCode, null, null) { } public SftpException(StatusCode statusCode, string message) : this(statusCode, message, null) { } public SftpException(StatusCode statusCode, string message, Exception innerException) : base(string.IsNullOrEmpty(message) ? GetDefaultMessage(statusCode) : message, innerException) { StatusCode = statusCode; } [System.Runtime.CompilerServices.NullableContext(1)] private protected static string GetDefaultMessage(StatusCode statusCode) { switch (statusCode) { case StatusCode.Ok: return "The operation completed successfully."; case StatusCode.NoSuchFile: return "A reference was made to a file that does not exist."; case StatusCode.PermissionDenied: return "The user does not have sufficient permissions to perform the operation."; case StatusCode.Failure: return "An error occurred, but no specific error code exists to describe the failure."; case StatusCode.BadMessage: return "A badly formatted packet or SFTP protocol incompatibility was detected."; case StatusCode.OperationUnsupported: return "An attempt was made to perform an operation which is not supported."; default: return statusCode.ToString(); } } } }