theophilusx / ssh2-sftp-client

a client for SSH2 SFTP
Apache License 2.0
808 stars 199 forks source link

No such file error while using put method #498

Closed jeremy-brooks closed 1 year ago

jeremy-brooks commented 1 year ago

Version: 9.1.0 Node: 18 Environment: AWS lambda

I am receiving an error indicating that the file I'm uploading or the location I'm uploading to does not exist, but I know this is not true.

I have used the this libraries exists and list methods to test if the upload location exists and what is there and to prove auth is ok, both of which return "d" and "file list" respectively, so happy that connectivity is ok.

I am getting the file from s3 that I'm trying to upload, which is also working fine.

So I am left with the put method issue.

I have now tried 3 variations of the same method: put(Buffer, sftpLocationIncludingFileName) put(localPathToTempFile, sftpLocationIncludingFileName) put(ReadableStream, sftpLocationIncludingFileName)

All 3 have the same error message:

 {
  "errorType": "Error",
  "errorMessage": "No such file.",
  "trace": [
    "Error: No such file.",
    "    at 101 (/opt/nodejs/node_modules/ssh2/lib/protocol/SFTP.js:2854:19)",
    "    at SFTP.push (/opt/nodejs/node_modules/ssh2/lib/protocol/SFTP.js:278:11)",
    "    at CHANNEL_DATA (/opt/nodejs/node_modules/ssh2/lib/client.js:587:23)",
    "    at 94 (/opt/nodejs/node_modules/ssh2/lib/protocol/handlers.misc.js:930:16)",
    "    at Protocol.onPayload (/opt/nodejs/node_modules/ssh2/lib/protocol/Protocol.js:2052:10)",
    "    at GenericDecipherBinding.decrypt (/opt/nodejs/node_modules/ssh2/lib/protocol/crypto.js:1418:26)",
    "    at Protocol.parsePacket [as _parse] (/opt/nodejs/node_modules/ssh2/lib/protocol/Protocol.js:2021:25)",
    "    at Protocol.parse (/opt/nodejs/node_modules/ssh2/lib/protocol/Protocol.js:306:16)",
    "    at Socket.<anonymous> (/opt/nodejs/node_modules/ssh2/lib/client.js:775:21)",
    "    at Socket.emit (node:events:514:28)"
  ]
}

I have also tried with some simple text content using a simple string for the content and then wrapping that in Buffer.from(), but same results.

jeremy-brooks commented 1 year ago

I have found the issue and it turned out to be unrelated to the put method, which was working fine in the end. Some log output caused a little misdirection on this one which was from our own code base. Working as expected now.