DLSFTPClient icon indicating copy to clipboard operation
DLSFTPClient copied to clipboard

Unable to stat file when uploading

Open Taxxodium opened this issue 10 years ago • 1 comments

When you initiate an upload, the library will return an error about being unable to stat the file even though the file was uploaded successfully.

The part where this happens is in the file DLSFTPUploadRequest.m around line 275

I've tried fixing it but without any luck.

Here's the code I've been playing with:

// stat the remote file after uploading LIBSSH2_SFTP_ATTRIBUTES attributes; while ( ((result = libssh2_sftp_fstat(self.handle, &attributes)) == LIBSSH2SFTP_EAGAIN) && self.isCancelled == NO){ waitsocket(socketFD, session); } if ([self ready] == NO) { [self.connection requestDidFail:self withError:self.error]; return; }

// result is always LIBSSH2_ERROR_SFTP_PROTOCOL if (result == LIBSSH2_ERROR_SFTP_PROTOCOL) { result = libssh2_sftp_last_error([self.connection sftp]);

// usually result at this point is LIBSSH2_FX_FAILURE if (result != LIBSSH2_FX_OK) { result = libssh2_sftp_stat([self.connection sftp], [self.remotePath UTF8String], NULL); } }

Taxxodium avatar Oct 27 '14 19:10 Taxxodium

Originally notified via email, responded with:

t looks like the error is coming from here. If you can set a breakpoint and confirm, that would be great:

https://github.com/dleehr/DLSFTPClient/blob/533f6c9b6d7380451c9dabeade5b568e537b3bf7/DLSFTPClient/Classes/DLSFTPUploadRequest.m#L276

After the file is transferred, DLSFTPClient tries to stat the file - to get its attributes on the server - file size, permissions, type, etc. http://www.libssh2.org/libssh2_sftp_fstat_ex.html. If this fails, the request fails (even though the file likely uploaded).

Error -31 is LIBSSH2_ERROR_SFTP_PROTOCOL (defined in libssh2.h). It means there was an error at the protocol level, but it looks like we need a call to libssh2_sftp_last_error to get the underlying reason.

I found a similar case here: http://www.libssh2.org/mail/libssh2-devel-archive-2010-04/0108.shtml where the underlying reason was NO_SUCH_FILE. So maybe the file is being uploaded to a symlinked directory and the stat isn’t working there?

dleehr avatar Nov 03 '14 14:11 dleehr