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.

Trying to `put` but `stat()` callback is returning undefined for both `err` and `stats`

See original GitHub issue

I receive an error when the code reaches https://github.com/theophilusx/ssh2-sftp-client/blob/master/src/index.js#L277 because the stats object is undefined. I don’t have details about the remote server (yet) which is controlled by a third party, but perhaps you may have some instinct as to why the callback for this.sftp.stat would return undefined for both err and stats arguments.

- Version of node? ==> v12.18.4
- Version of ssh2-sftp-client? ==> latest
- Platform client is on? ==> N/A
- Platform remote sftp server is on? ==> N/A

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
theophilusxcommented, Oct 23, 2020

Thanks for doing that, really appreciated.

This was my suspicion.

A couple of versions back, I added a lot of additional error checking to try and provide more informative error messages to the client. Many of the error messages from ssh2/ssh2-streams are not particularly informative and led to user confusion (e.g. error messages such as ‘Failure’).

To do this, I added code to do things like verify remote files exist or don’t exist or remote target is a file or a directory etc. This allowed me to provide better error messages that helped users and based on the drop in basic issues, this seems to have worked.

Unfortunately, this has had two undesirable side effects. Firstly, not all sftp servers are equal and some don’t support stat, realPath and listing. While these servers are in the minority, they do exist. The second problem is that this also has a bit of a hit on performance. The hit on performance is particularly noticeable on slow connections.

So I made the decision to remove all this additional error checking in the next version. At the same time, the ssh2 module is getting a complete re-write (so I’m hoping I might be able to convince the maintainer to add/improve error messages where necessary). The ssh2-streams library is being deprecated and its functionality moved into the main ssh2 module.

So the next version will work with sftp servers like the one you are using. Unfortunately, I have to wait for some of the additional functionality (like streams) to be added to ssh2. The ssh2 author says to use ssh2-streams if you still need stream support, but one of the reasons for the ssh2 re-write is that ssh2-streams does not work correctly with node v14+. It is likely I may need to re-think some of the design and API to work with the new ssh2 and I will need to wait until the new ssh2 reaches production readiness before a new version can be released. If this takes too long, I might have to release an intermediate versions which has removed the additional error checking, but still uses the existing ssh2/ssh2-streams modules (which means no node v14+ support).

I’ve started working on the new versions as the branch version-6 in the git repository. The new version should work with sftp servers like the one your using, but it won’t be production ready for quite some time.

0reactions
rosschapmancommented, Oct 23, 2020

Ok I had a few minutes and went back and opened a connection and at the sftp> prompt played around with trying to stat the root directory where I’d been trying to upload files. That server does not support stat but supports df and trying that I received this helpful error message: Server does not support statvfs@openssh.com extension. I suspect this is relevant and there may be guards on the server to prevent reading the filesystem stats?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express, calling then() function second times, return ...
I want to sending data to nats streaming server with publisher function. For that I need a second then then function on mongoose...
Read more >
oWaiting metric not showing properly when querying
Statistics are only returned if they have a value. Consider the server-side logic like this: For cases where no conversations meet the criteria ......
Read more >
Using the Response Object - AWS SDK for JavaScript
After a service object method has been called, it returns an AWS.Response object by passing it to your callback function. You access the...
Read more >
JavaScript Interview Questions & Answers
The slice() method returns the selected elements in an array as a new array object. ... error is encountered, If you try to...
Read more >
LLVM Programmer's Manual - Documentation
Introduction¶. This document is meant to highlight some of the important classes and interfaces available in the LLVM source-base. This manual is not ......
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