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.

SFTP: FastGet returning Folder not found error

See original GitHub issue

I’m having trouble downloading a file with the sftp fastGet method. Here is my code:

  var client = new Client();
  client.on('ready', function() {
    client.sftp(function(err, sftp) {
      sftp.fastGet('./file.zip', 'file.zip', function(err) {
        client.end();
      });
    });
  }).connect({
    *connection_info*
  });

I am getting the following error:

Error: Folder not found: \remote\pathHome\directory\file.zip

If I do a readdir: sftp.readdir('./', function(err, filelist) { console.log(filelist); });

It lists file.zip as one of the files.

And if I do a realpath: sftp.realpath('./', function(err, absPath) { console.log(absPath); });

It returns /home/directory (note the lowercase h on home)

I am not the administrator of the sftp server so can only assume that the \remote\path part of the error is some internal directory structure on the server.

Using node v4.2.1 and ssh2 v0.4.12

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
EduardoIbarracommented, Dec 27, 2019

I’m having the same problem. If I use the .list() method, it gives me the list of files, but when I try to do a getFast, it says that the files do not exist.

0reactions
theophilusxcommented, Oct 11, 2022

This looks like it is ssh2-sftp-client, not ssh2?

At any rate, I suspect you have a bug in your code. In the then block of your promise chain, the call to client.fastGet() needs to be proceeded with a return statement. Without the return statement, your actually starting a whole new promise chain. In your original code, because the fastGet() call was in its own promise chain, the client.end() call was occurring before the fastGet() call was fulfilled. The client.end() call knows nothing about the fastGet() call as it is in a separate chain, so does not wait for it to be fulfilled. Removing the call to end allows the fastGet() call to be fulfilled, but now you have no way of knowing when the work is done and can close the connection. Add the return statement and the call to client.fastGet() becomes part of the promise chain, so client.end() will wait until it is fulfilled before ending the connection.

Change your code to

let remotePath = './pix2pix-tensorflow/invokator_test/images/001-outputs.png';
let localPath = './001-outputs.png';

client.connect(config)
    .then(() => {
        return client.fastGet(remotePath, localPath);
    })
    .then(() => {
       return client.end();
     })
    .catch(err => {
        console.error(err.message);
    });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js - ssh2-sftp-client getting multiple files error
What I believe is currently happening is that since you're not returning a Promise from your second then() , the third then() gets...
Read more >
ssh2-sftp-client - npm
If the remote file did not exist, the method would return an error, but failed to close any passed in stream supplied as...
Read more >
ssh2-sftp-client-fork - npm Package Health Analysis | Snyk
The realPath() method now returns '' if the path does not exist rather than throwing an exception. Improved error handling.
Read more >
Files changed (6) - Renovate Bot Package Diff
The realPath() method now returns `''` if the path does not exist rather than ... At least one SFTP server (Azure SFTP) seems...
Read more >
npm:ssh2-sftp-client-mkdir-patch - Skypack.dev
the connection to server config pls see ssh2 client event. list of methods: all the methods will return a Promise;. List. Retrieves a...
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