-
Notifications
You must be signed in to change notification settings - Fork 599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net.schmizz.sshj.sftp.SFTPException: "Handle not Found" when Attempting to Upload a File #169
Comments
@dkocher My mistake, sorry! Has the version with the fix been released? I'm currently referencing version 0.10.0 |
Thx @dkocher, indeed exactly the same. |
@MusikPolice There is no newer version yet than 0.10.0. Currently working on that. |
@MusikPolice Version 0.11.0 is now released, which should fix this. Please look at the README, or the announcement here: https://groups.google.com/forum/#!topic/sshj-users/ZvFB6gZCoyI Closing this issue. |
When attempting to upload a file to an SFTP server, I get a "Handle Not Found" error. The stack trace looks something like this:
A little bit of research turned up this Google Groups post that claims that the target server returned an 8-byte file handle to the client, which in turn sent a 12-byte string to back the server when trying to write the file contents.
I wrote a simple unit test to prove this theory, and found that it made some sense:
In this case, the sourceBytes array and the rpos=5 variables came from my debugger. To get them, I set a breakpoint in the
open
method inSFTPEngine
(line 137) and stepped into thereadString()
method of theBuffer
class (line 336) to see how the server's response was being parsed.According to the SFTP RFC, the response to an
SSH_FXP_OPEN
message is anSSH_FXP_HANDLE
message that contains an integerid
field and a stringhandle
field. The RFC describes this message thusly:The thing is, I think that SSHJ is modifying the handle - The
readString()
method in theBuffer
class attempts to convert the handle into a UTF-8 string. This is fine if each of the bytes in the handle can be represented in this encoding, but the javadoc for theString()
constructor that is used byreadString
specifically states that "the behavior of this constructor when the given bytes are not valid in the given charset is unspecified".Later, in the
newRequest
method of theRemoteResource
class (line 46), the handle is turned back into a byte array by theputString
method in theBuffer
class (line 401). My unit test shows that extracting the bytes from the string handle results in the 12-byte array that the original Google Groups post was complaining about.In short, I think that the way to fix this problem is to always treat the handle that is returned in the
SSH_FXP_HANDLE
message as a byte array, rather than bashing it into a UTF-8 string, as I suspect that some SFTP servers return a handle that cannot be encoded in this manner.The text was updated successfully, but these errors were encountered: