ssh2-sftp-client: sftp.realPath: No such file Error when there is definitely a file.
Node --version 12.10.0 typscript – version 3.6.2 ssh2-sftp-client 4.2.1
Error: sftp.realPath: No such file /Outgoing/CommissionStmts/00001.pdf
The above error is thrown every time I attempt to get/ fastget/stat/exists any files. I have visually inspected that the file & file paths are correct and that I have the correct permissions I did this by using filezilla to log into the server and pull the file from the same IP address using the same set of Credentials. below is a extract from my code:
-index.ts
import Client from "ssh2-sftp-client";
class CommissionStatement{
ftp:Client = new Client();
public async GetFile(){
await this.ftp.connect({
host: "sftp.host.com",
port: 22,
username: "user",
password: "pass",
readyTimeout: 65000
});
let remoteDir = '/Outgoing/CommissionStmts/';
let list = await this.ftp.list(remoteDir );
/* this is to prove I can access the directory, it's also known that I have all permissions for all files and directories. */
console.log(list[0]);
let remoteFullPath = remoteDir+"00001.pdf"
let file = await this.ftp.get(remoteFullPath ,localFilePath).catch((error)=>{throw error})
/*the above line throws the error everytime.*/
}// end GetFile()
}//end class
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 30 (18 by maintainers)
so for what it’s worth I just ran into this today. Worked fine with 6.x on a local windows machine, but when running in a lambda it would list the files but error out on fastGet with “file not found”. stat and exists both worked though. downgrading to 2.4.3 fixed the issue and it worked fine in the lambda (and still worked locally), but I will poke around and see if there’s a way to resolve that doesn’t involve downgrading to a much older version
Thanks for your input @theophilusx , I simplified and added async/await try/catch as you suggested with the same result.
The error:
I made sure the file exists and that I am using the same format/path as the list() method gives me. Also I connected using a gui client to list and download files with the same connection parameters as in my code. So I think this might be a Windows incompatibility issue. Thank you for all the help!