-
Notifications
You must be signed in to change notification settings - Fork 379
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
Fstat returns error "Folder not found: c:\xxx\yyy.csv" (SSH_FX_FAILURE) on a file #288
Comments
I discovered who calls the Lines 886 to 895 in 5bcd86d
Which is called by rclone to maximise the throughput of the download. |
Hey @ncw, thanks for reporting the issue. I skimmed through the forum discussion you linked and to be sure of the situation, let me re-iterate and clarify a few points.
|
Sure
In a recent beta I put a log in to discover the name of the server - I'll ask the user to run that.
The file is being copied from the SFTP server to local disk, so it is being downloaded.
Yes and the file exists too. The file can be
The workaround I attempted (which didn't work) was to use |
It seems like I misread parts of that thread pretty badly. Thanks @ncw for clarifying things and giving more details. Sorry it's taking me a while to look into this. I just started a new job and have been pretty busy. I'll try to spend more time on it soon. |
@ncw Sorry for being obtuse, but...
The directories and file already exist on the client where it is being downloaded to, on the server where it is being downloaded from or both? |
The directories and files exist on the server. Rclone will create directories as needed on the client before it downloads the file. PS While investigating this problem I had a deeper look at the source and discovered it could be an sftp server! That encouraged me to write rclone serve sftp which can server any of rclone's supported cloud providers (including local disk) as sftp. The library was a joy to work with, so thank you very much for that :-) |
I am seeing a very similar sounding issue, but on downloading files from an external SFTP server (over which I have no control). This is also using rclone but the issue appears to be with the behavior of the underlying sftp module. The SFTP server in question ("SSH-2.0-SSHD-CORE-0.13.0", for those playing along at home) returns an SSH_FX_FAILURE error for the stat call. A quick-n-dirty hack was to remove the call to stat and set If this is an appropriate fix, I'm happy to raise a PR. |
Interesting... Can you paste the diff? |
Here you go (I did say it was quick-n-hacky... 😄 ) diff --git a/vendor/github.com/pkg/sftp/client.go b/vendor/github.com/pkg/sftp/client.go
index ef885d801..0045ccd4e 100644
--- a/vendor/github.com/pkg/sftp/client.go
+++ b/vendor/github.com/pkg/sftp/client.go
@@ -884,15 +884,15 @@ func (f *File) Read(b []byte) (int, error) {
// maximise throughput for transferring the entire file (especially
// over high latency links).
func (f *File) WriteTo(w io.Writer) (int64, error) {
- fi, err := f.Stat()
- if err != nil {
- return 0, err
- }
+ //fi, err := f.Stat()
+ //if err != nil {
+ // return 0, err
+ //}
inFlight := 0
desiredInFlight := 1
offset := f.offset
writeOffset := offset
- fileSize := uint64(fi.Size())
+ fileSize := uint64(f.c.maxPacket)
// see comment on same line in Read() above
ch := make(chan result, f.c.maxConcurrentRequests+1)
type inflightRead struct { |
Thanks! That is exactly the same bit of code that was causing the original issue. Does this slightly less hacky patch work for you? diff --git a/vendor/github.com/pkg/sftp/client.go b/vendor/github.com/pkg/sftp/client.go
index ef885d801..11a81b5e0 100644
--- a/vendor/github.com/pkg/sftp/client.go
+++ b/vendor/github.com/pkg/sftp/client.go
@@ -884,7 +884,7 @@ func (f *File) Read(b []byte) (int, error) {
// maximise throughput for transferring the entire file (especially
// over high latency links).
func (f *File) WriteTo(w io.Writer) (int64, error) {
- fi, err := f.Stat()
+ fi, err := f.c.Stat(f.path)
if err != nil {
return 0, err
} |
Yep it does indeed (at least as well as my hacky patch did).
|
@eikenb Do you think the above patch would be acceptable if I sent a PR with it in? I think it
However it is a work-around for what is probably a broken SFTP server. |
@ncw FYI I've tested this patch against a known-problematic WS_FTP server (same as the original rclone problem report) and it resolves the issue there, too. |
While I think this should be fine I'm now thinking the fix is to just remove that Stat check entirely. None of the other read/write methods (Read, Write, ReadFrom) have that check, only WriteTo does, and I'm not sure I see any reason it needs it while the other's do not. |
Before this change in File.WriteTo() we used Fstat to discover the length of the file being transferred. It appears that some SFTP servers do not implement this properly perhaps because it is a seldom used call. After this change we replace the Fstat on the file handle with a Stat of the path. Stat is commonly used function and implemented correctly in both the servers that had the problem with Fstat, thus working around the problem. The code before and after uses the same number of SFTP roundtrips so performance should be identical. Fixes pkg#288
I created a pull request for the one line fix above #289 |
@eikenb sorry missed your message!
The Stat is used read the file size, which in turn in used only to control the if offset > fileSize {
desiredInFlight = 1
} We'd need to know that the read had finished and turn down the window. I'm not sure how to accomplish that since there doesn't seem to be an EOF message when reading the data from the remote end. |
Of course you are right about the filesize and I think your solution is fine. I'll take it for now to resolve the issue. It still bugs me that it is needed though as it doesn't really seem like it should be, it should receive an EOF and finish up just like ReadFrom. But I don't have the time to play with it right now and your PR fixes it. |
An rclone user has reported that rclone with a certain sftp server reports the error
"Folder not found: c:\xxx\yyy.csv" (SSH_FX_FAILURE)
. As far as I can work out this is being generated by theRead()
call on an open file, though looking at the trace below it seems to come fromFstat
on the open file - not sure what is calling that.The user reports that other sftp clients work just fine.
I turned on debugging and sent the user a binary to try.
Here is rclone logs interleaved with sftp debugs
Rclone has identified the file as needing to transfer
Now we open it
However the SSH_FXP_FSTAT returned an error. I don't know why! Rclone doesn't directly call
Stat()
on the handle returned - I'm not sure where that gets called.I attempted to decode the sftp debug using the RFC but it wasn't making sense, so I'm asking for help here.
Thanks in advance!
The text was updated successfully, but these errors were encountered: