cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: SFTP and CURLOPT_RANGE

From: Wei Weng <wweng_at_acedsl.com>
Date: Fri, 12 Sep 2008 00:40:30 -0400

Ian Lynagh wrote:
> Hi all,
>
> I would like to use CURLOPT_RANGE with an SFTP download, but it's not
> currently supported. However, looking at
> http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#page-36
> I saw that the protocol supports it, so I've tried to add support.
>
> The patch below makes curl start downloading from the right byte, so I'm
> half way there. Unfortunately, due to unfamiliarity with the code, I
> haven't managed the other half yet, and I don't have any more time to work on
> this at the moment. Presumably all that is needed is to tell curl how
> many bytes to download, somehow. I'd be delighted if someone was able to
> finish this off, or give me some clues on how to do so myself.
>
> The patch is against Debian's 7.18.2 as that's what I had handy, but I
> hope it'll work equally well in the CVS code.
>
> diff -ur old/curl-7.18.2/lib/ssh.c new/curl-7.18.2/lib/ssh.c
> --- old/curl-7.18.2/lib/ssh.c 2008-05-31 07:15:01.000000000 +0100
> +++ new/curl-7.18.2/lib/ssh.c 2008-09-12 01:34:47.000000000 +0100
> @@ -104,6 +104,7 @@
> #include "select.h"
> #include "parsedate.h" /* for the week day and month names */
> #include "sockaddr.h" /* required for Curl_sockaddr_storage */
> +#include "strtoofft.h"
> #include "multiif.h"
>
> #if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
> @@ -2306,6 +2307,20 @@
> }
> *connected = conn->bits.tcpconnect;
>
> + if(conn->data->state.use_range) {
> + curl_off_t from, to;
> + char *ptr;
> + char *ptr2;
> +
> + /* XXX This needs to look for from/to being missing */
> + from=curlx_strtoofft(conn->data->state.range, &ptr, 0);
> + while(ptr && *ptr && (isspace((int)*ptr) || (*ptr=='-')))
> + ptr++;
> + to=curlx_strtoofft(ptr, &ptr2, 0);
> +
> + libssh2_sftp_seek(conn->proto.sshc.sftp_handle, from);
> + }
> +
> if(*dophase_done) {
> DEBUGF(infof(conn->data, "DO phase is complete\n"));
> }
>
>
> Thanks
> Ian
>
>

Dear Ian:

Can not you use SSH_FXP_STAT to get the file size?
(http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.5)

And then deduct the range from the size to get the length you wanna
download/upload from the file.

While you are at it, hmm, seems byte range lock of the file should be trivial
to implement too.

http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.8

Thanks
Wei
Received on 2008-09-12