question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why can't this create a new file on the remote server? "no such file or directory"

See original GitHub issue

The issue is present in the example code for me

let Client = require('ssh2-sftp-client');
let sftp = new Client();

sftp.connect({
    host: '...',
    port: '...',
    username: '...',
    password: '...'
}).then(() => {
    return sftp.fastPut('./test.txt', '/tf/maps/test.txt') //this doesn't work unless a '/tf/maps/test.txt' already exists which it will overwrite
    //return sftp.put(require(`fs`).createReadStream('./test.txt'), '/tf/maps/test.txt') //Same issue as above
    //return sftp.list('/tf/maps/') //This works
}).then(data => {
    console.log(data, 'the data info');
}).catch(err => {
    console.log(err, 'catch error');
});

I get the error Error: fastPut->exists->_stat: open /var/lib/pufferd/servers/18a5d777-a56d-4d07-a6f4-7d0e3f619081/tf/maps/test.txt: no such file or directory /tf/maps/test.txt for fastPut and put, unless I already have a test.txt on the remote server. Does this package only overwrite existing files? I have no idea how to actually create a remote file In the readme it says remotePath: string. Path to the remote file to be created on the server. which suggests that it should create the file yet refuses to write unless it’s already there.

I have the server open in Filezilla and am able to create files there so I don’t think it’s a permission issue. I have also tried explicitly giving the flag w , and tried different modes as if that would do anything

Node: 14.7.0 OS: tried on Windows 10, Debian 4.19.118, and Ubuntu 18.04.4 ssh2-sftp-client: 5.2.1 Server is using https://github.com/PufferPanel/pufferd

Full errors:

Error: put->exists->_stat: open /var/lib/pufferd/servers/18a5d777-a56d-4d07-a6f4-7d0e3f619081/tf/maps/test.txt: no such file or directory /tf/maps/test.txt
    at Object.formatError (C:\Users\x\source\repos\sftptest\sftptest\node_modules\ssh2-sftp-client\src\utils.js:62:18)
    at SftpClient.put (C:\Users\x\source\repos\sftptest\sftptest\node_modules\ssh2-sftp-client\src\index.js:740:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  code: 'ERR_GENERIC_CLIENT',
  custom: true
} catch error
Error: fastPut->exists->_stat: open /var/lib/pufferd/servers/18a5d777-a56d-4d07-a6f4-7d0e3f619081/tf/maps/test.txt: no such file or directory /tf/maps/test.txt
    at Object.formatError (C:\Users\x\source\repos\sftptest\sftptest\node_modules\ssh2-sftp-client\src\utils.js:62:18)
    at SftpClient.fastPut (C:\Users\x\source\repos\sftptest\sftptest\node_modules\ssh2-sftp-client\src\index.js:652:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  code: 'ERR_GENERIC_CLIENT',
  custom: true
} catch error

Debug of fastPut https://pastebin.com/8AfrzSwE

When I already made a blank test.txt

test.txt was successfully uploaded to /tf/maps/test.txt! the data info

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
theophilusxcommented, Aug 11, 2020

Fix released in v5.2.2

1reaction
theophilusxcommented, Aug 8, 2020

Just looking more closely at the error message and the server code, can you verify the server supports the stat() method e.g.

sftp.stat(/path/to/remote/file’);

I suspect the command is not supportedor it is returning data in a non-comnpliant manner.

run the command with argument for a file which exists, a file which does not exist and a directory which exists. Send me the results.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix 'No such File or Directory' Error in SCP? - Appuals
What Causes the “No Such File or Directory” Error in SCP? · Incorrect Command: In some cases, the command that is being used...
Read more >
No Such File Or Directory In SCP: How To Fix The Error
Login is not correct: the SCP error could occur when you are trying to copy files to certain desktop after you have logged...
Read more >
scp files from local to remote machine error: no such file or ...
It's because the folder where the file was contained space in its name... Share.
Read more >
No such file or directory error after creating a new file #212
When I connected to Remote FTP server and try to create a new file, it prompt the error "No such file or directory",...
Read more >
"No such file or directory" error when attempting to copy (using ...
Similarly, I have been unable to use scp to copy files to my remote host. Any help with this issue is highly appreciated,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found