cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Curl and GXS SFTP

From: Marc Renault <marcpaulrenault_at_gmail.com>
Date: Tue, 16 Dec 2014 09:19:14 +0100

I just tested a zero byte file and it works fine. Plus, it doesn't give the
"file already completely downloaded" message which I think has more to do
with continuing a prior download.

To avoid copying and pasting code, I changed the if statement at
2095:ssh.c. I thought it would be good to check whether or not the size was
returned just in case filesize was populated with garbage and then also
test if the file had size 0.

The change I did in the end was:

--- ssh.c 2014-12-16 09:12:15.947601932 +0100
+++ ssh.c.fix 2014-12-16 09:16:47.426812069 +0100
@@ -2092,10 +2092,13 @@
       if(rc == LIBSSH2_ERROR_EAGAIN) {
         break;
       }
- else if(rc) {
+ else if(rc || !(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE)
+ || attrs.filesize == 0) {
         /*
          * libssh2_sftp_open() didn't return an error, so maybe the server
          * just doesn't support stat()
+ * OR the server doesn't return a file size with a stat()
+ * OR file size is 0
          */
         data->req.size = -1;
         data->req.maxdownload = -1;

Marc

On 15 December 2014 at 22:52, Daniel Stenberg <daniel_at_haxx.se> wrote:
>
> On Thu, 11 Dec 2014, Marc Renault wrote:
>
> Thanks for your research!
>
> Based on the previous posts, I did some digging to see what is going on
>> with the libssh2_sftp_stat_ex call at ssh.c:2089. From what I can tell,
>> the
>> call works fine. But the flags that are set are only:
>> SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004
>> SSH_FILEXFER_ATTR_ACCESSTIME 0x00000008
>> That is the value of attrs.flags is 12.
>>
>
> Essentially, the code handles the case where there server doesn't respond
>> to the SSH_FXP_STAT but doesn't consider the case that a server might
>> respond to SSH_FXP_STAT without a file size. My proposed fix is the
>> following:
>>
>
> Hm, it isn't a totally bad work-around as it seems an SFTP client
> shouldn't make assumptions of what data that is returned. Have you tried
> downloading a zero byte file with this work-around applied?
>
> --
>
> / daniel.haxx.se
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-12-16