SFTP Permission Denied trying to open existing file.


Question:

Why did I get a permission denied error from the server when trying to open an existing file on the SSH/SFTP server? Here’s the LastErrorText:

ChilkatLog:
   DownloadFileByName:
     DllDate: Dec  2 2009
     UnlockPrefix: ***
     Username: Administrator
     Component: ActiveX
     SshVersion: SSH-2.0-CoreFTP-0.1.2
     SftpVersion: 3
     PreserveDate: 0
     fromFilePath: /test.dat.gz
     toFilePath: c:\abc\test.dat.gz
     OpenRemoteFile:
       filename: /test.dat.gz
       access: readOnly
       createDisposition: openExisting
       v3Flags: 0x1
       Sent FXP_OPEN
       StatusResponse:
         Request: FXP_OPEN
         StatusCode: 3
         StatusMessage: Permission denied
       SshLog: 
 SFTP> Sending SSH_FXP_OPEN
 TRAN> CHANNEL_DATA
 TRAN* NumBytes: 59
 TRAN< CHANNEL_DATA
 SFTP< Received SSH_FXP_STATUS

       timeToOpenMs: Elapsed time: 31 millisec
     totalTimeMs: Elapsed time: 31 millisec
     Failed.

Answer:

You are trying to download “/test.dat.gz” from the SSH/SFTP server. Some servers interpret the leading “/” as the root directory of the SSH user account. However, some servers interpret it as the root directory of the default drive (i.e. default filesystem). Your SSH/SFTP server is doing the latter. Your SSH/SFTP user account apparently does not have permission to read the root directory of the default filesystem, and therefore you get a “permission denied”. The solution is to download “./test.dat.gz” to clearly indicate that test.dat.gz is located in the HOME directory of the SSH/SFTP user account.