SFTP Server Responds with SSH_FX_NO_SUCH_FILE when trying to OpenFile

If your application calls Chilkat’s SFtp.OpenFile, and it fails because the server responded with SSH_FX_NO_SUCH_FILE, it means the file does not exist on the server. Trust that this is correct — the server would not say so unless the remote file truly does not exist on the server at the path your application provided.

All remote file paths passed to an SFTP server must be either (1) a full absolute path from the root of the server filesystem, or (2) a remote path relative to the $HOME directory of the SSH user account being used. There is no concept of “state” or “current directory” in SFTP as there is in the FTP protocol.

It’s also possible that the remote filesystem is case-sensitive. Check the path carefully to make sure it exactly matches what exists on the server.

Explaining how FTP has “state”, but SFTP does not

The FTP (File Transfer Protocol) and SFTP (SSH File Transfer Protocol) are both protocols used for file transfer, but they differ in their underlying mechanisms and features. One of the key differences between them is how they handle the concept of state, including the current directory.

FTP Protocol:

The FTP protocol is a stateful protocol, which means it maintains a session state between the client and the server. The state includes information such as the current directory (working directory) on the server, authentication credentials, and other session-related parameters.

When a client establishes an FTP connection with a server, it goes through a series of commands to authenticate, set up the data transfer mode, and navigate the server’s file system. The server maintains the current directory state for the client, so subsequent file operations are performed relative to the current directory.

For example, if the client sends a command to upload a file without specifying the full path, the server assumes the file should be uploaded to the current directory. The client can change the current directory using commands like `CWD` (Change Working Directory) or `PWD` (Print Working Directory) to navigate through the server’s file system.

SFTP Protocol:

On the other hand, the SFTP protocol is a subsystem of the SSH (Secure Shell) protocol and operates over an SSH connection. Unlike FTP, SFTP does not have an inherent concept of state or a current directory.

In SFTP, every file operation includes the full path to the file or directory on the server (or use “./path” to imply a path relative to the $HOME directory of the SSH user account, or a path that does not begin with “/” to imply a path relative to the $HOME directory). The client explicitly specifies the file paths for each operation, such as uploading, downloading, or navigating the file system. The server does not maintain any state about the current directory or session-related information.

When using SFTP, the client needs to provide the full path to the file or directory for any operation. For example, if the client wants to upload a file, it must specify the complete path where the file should be stored on the server.

Tags :