Comments (5)
Try getLastSFTPError()
.
When I try to upload a file to a directory that doesn't exist the server responds, on the SFTP layer, with an SSH_FXP_STATUS message with an error/status code of SSH_FX_NO_SUCH_FILE and an error message of "No such file".
Ultimately, however, phpseclib is just reporting on what the server is saying. If the server is silently failing there isn't a whole lot that phpseclib can do to glean information about that.
But, in this case, I suspect the server isn't silently failing and that you're just calling the wrong method.
from phpseclib.
I do find it somewhat confusing that the getLastError
and getLastSFTPError
are separate methods, but it does appear I was just using the wrong method.
from phpseclib.
I do find it somewhat confusing that the
getLastError
andgetLastSFTPError
are separate methods
It might be something to consider changing for phpseclib 4.0+ as backwards compatibility won't be an issue in that version.
As for why it has the design that it currently does... so SFTP operates at a layer above the SSH layer. So in SSH you have SSH_MSG_CHANNEL_DATA packets, among other packet types. SFTP packets are contained within SSH_MSG_CHANNEL_DATA packets. An SFTP packet may span multiple SSH_MSG_CHANNEL_DATA packets or there could be multiple SFTP packets in one SSH_MSG_CHANNEL_DATA, it all depends.
Because one is embedded in the other it makes sense to have separate logs. So like if you have the SSH logs you can extract the SFTP logs since SFTP packets are embedded within SSH packets but you can't get SSH packets from SFTP packets.
getLastError
and getLastSFTPError
are split for those same reasons. If the server sends an SSH_MSG_DEBUG packet to the client that's logged in getLastError
. Even if SSH_MSG_DEBUG doesn't contain an error, per say, it none-the-less, ends up in getLastError
. Likewise, if the server sends a SSH_MSG_GLOBAL_REQUEST packet to the client phpseclib will reject it and log the request name in getLastError
. If the server sends an exit-signal SSH_MSG_CHANNEL_REQUEST then the signal name is logged in getLastError
and, if the packet contains, the error message.
Basically, it reports on debug info reported on by the server. So like if phpseclib can't read a RSA private key that's not gonna be in getLastError
- that'll throw an exception. phpseclib doesn't throw an exception if getLastError
is updated because, honestly, it might not rise to the level of an exception anyway.
Similarly, getLastSFTPError
returns information returned by the SFTP layer. So SFTP packets are prefixed in the SFTP specs by SSH_FXP_*. So consider get()
. phpseclib sends 32x SSH_FXP_READ packets (all contained within SSH_MSG_CHANNEL_DATA packets) for successive parts of a file and should get back 32 or less SSH_FXP_DATA packets (this is done for speed and is also done by PuTTY / WinSCP / etc). If it gets less then 32 SSH_FXP_DATA packets then it should get 32 SSH_FXP_STATUS packets back less the number of SSH_FXP_DATA packets that it got back. If it receives an SFTP packet that isn't either of those an exception is thrown.
An SSH_FXP_STATUS packet contains a 32-bit integer value representing the error/status code and a string representing the error message. So unless the file being read is exactly a multiple of 1MB (32KB*32) then you'll get a bunch of absolutely non-fatal message about how the requested file offset is invalid because it's larger then the size of the file or some such.
Should SFTP / SSH "messages" be grouped together? Maybe. But the fact that they're not can also give you clues as to where the error is specifically happening. I mean, I suppose I could preface SFTP layer messages with SFTP:
and SSH layer messages with SSH2:
and then you could look at the string to determine what's what.
I mean, I'm not opposed to changing it for a new version of phpseclib but, anyway, the above is why they (currently) exist as two separate methods. TLDR it's because it mirrors how SFTP operates at a different layer than SSH does.
from phpseclib.
Thank you for the detailed explanation. It does shed some light onto why it is that way.
Could I suggest a few additions to the documentation to help make the distinction more clear?
For getLastError
, I would suggest the following docstring:
Returns the last error received on the SSH layer.
If you are looking for messages from the SFTP layer, please instead see
getLastSFPTError
.
For getLastSFTPError
, I think the name already helps make the distinction clear, but it could be helpful to change it to:
Returns the last error received on the SFTP layer.
For me at least, when I was reading the documentation for the proper way to get error information, I came across getLastError
and (incorrectly) assumed from the name and description that was pretty clearly and obviously the method I needed, and therefore didn't continue looking to find getLastSFTPError
. Having something to signal the more limited scope of the method would have prompted me to keep looking.
from phpseclib.
See a69364d
from phpseclib.
Related Issues (20)
- Undefined variable $name in function addFileFormat HOT 2
- CVE-2023-48795 - Terrapin Vulnerability HOT 3
- Unintended change causes lint failing in dependent packages with latest v3.0.35 HOT 1
- Notice: Trying to access array offset on value of type bool in /src/vendor/phpseclib/phpseclib/phpseclib/Net/SFTP.php on line 2132 HOT 1
- a HOT 1
- Server Terminates Connection HOT 8
- add ssh3 support for faster connection HOT 1
- Using OpenSSH private key results in openssl_sign() - supplied key param cannot be coerced into a private key HOT 4
- ElGamal ECC encryption HOT 1
- Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) HOT 5
- Issue with isConnected/isAuthenticated after remote terminal restart HOT 5
- openssl_x509_check_private_key always return cert and privatekey mismatch HOT 2
- SSH2 exec crashes while returning data & "Please close the channel (1) before trying to open it again" HOT 9
- Semantic versioning? HOT 13
- Add setPaddable func at the SymmetricKey class? HOT 2
- 2.0.47 is a breaking change | `AES::setKey` interface changed HOT 1
- Server crashes before NET_SSH2_MSG_KEXDH_REPLY HOT 2
- SSH2: Decryption Failures During Read HOT 8
- Load ASN.1 private key to generate an RSA signature HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpseclib.