Skip to content

Add SftpException and SftpPathNotFoundException.Path - #1716

Merged
Rob-Hague merged 1 commit into
sshnet:developfrom
Rob-Hague:sftpexception
Oct 23, 2025
Merged

Add SftpException and SftpPathNotFoundException.Path#1716
Rob-Hague merged 1 commit into
sshnet:developfrom
Rob-Hague:sftpexception

Conversation

@Rob-Hague

Copy link
Copy Markdown
Collaborator

This adds an SftpException which sits between the existing SftpPathNotFoundException/SftpPermissionDeniedException and SshException, and which contains the response code from the SSH_FXP_STATUS packet, along with a default message if one was not provided.

SftpPathNotFoundException also gains a Path property which is populated in cases where it makes sense.

closes#161
closes#567

This adds an SftpException which sits between the existing SftpPathNotFoundException/
SftpPermissionDeniedException and SshException, and which contains the response code
from the SSH_FXP_STATUS packet, along with a default message if one was not provided.
SftpPathNotFoundException also gains a Path property which is populated in cases where
it makes sense.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new SftpException class as an intermediate exception type between existing SFTP-specific exceptions (SftpPathNotFoundException, SftpPermissionDeniedException) and the base SshException. The new exception includes a StatusCode property containing the response code from SSH_FXP_STATUS packets, along with default error messages when none are provided. Additionally, SftpPathNotFoundException now includes a Path property that captures the path that wasn't found.

Key changes:

  • Introduced SftpException with StatusCode property and default messages for common status codes
  • Added Path property to SftpPathNotFoundException to capture the missing path
  • Renamed StatusCodes enum to StatusCode and made it public (previously internal)

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
version.jsonBumped version from 2025.0.1 to 2025.1.0 to reflect the new feature
src/Renci.SshNet/Common/SftpException.csNew exception class with StatusCode property and default message generation
src/Renci.SshNet/Common/SftpPathNotFoundException.csChanged to inherit from SftpException, added Path property and path-aware message generation
src/Renci.SshNet/Common/SftpPermissionDeniedException.csChanged to inherit from SftpException instead of SshException
src/Renci.SshNet/Sftp/StatusCode.csRenamed and made public with added documentation (first 9 status codes)
src/Renci.SshNet/Sftp/StatusCodes.csRemoved (replaced by StatusCode.cs)
src/Renci.SshNet/Sftp/SftpSession.csUpdated to use new SftpException and pass path context for better error messages
src/Renci.SshNet/Sftp/Responses/SftpStatusResponse.csUpdated to use StatusCode enum and enabled nullable reference types
test filesUpdated tests to verify new StatusCode property and Path property behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadsrc/Renci.SshNet/Sftp/StatusCode.cs
Comment threadsrc/Renci.SshNet/Sftp/SftpSession.cs
@Rob-Hague
Rob-Hague merged commit cd9ec8f into sshnet:developOct 23, 2025
5 checks passed
@Rob-Hague
Rob-Hague deleted the sftpexception branch October 23, 2025 05:34
This was referenced Aug 12, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SftpPathNotFoundException doesn't contain the errored path Status codes returned by SFTP Server

3 participants

@Rob-Hague@WojciechNagorski