I'm trying to develop a simple PoC (Proof of Concept) to perform an sftp file upload that supports resume of partially transferred files.
Environemnt:
GNU/Linux Ubuntu 16.04 64b
libcurl 7.58.0 built with libssh2 support
gcc 5.4.0
I took as a starting point the code example: https://curl.haxx.se/libcurl/c/ftpuploadresume.html and modified it to:
The behavior I'm verifying is that once the connection is done:
I'm a bit confused by a comment as well:
/*
* With NOBODY and NOHEADER, libcurl will issue a SIZE
* command, but the only way to retrieve the result is
* to parse the returned Content-Length header. Thus,
* getcontentlengthfunc(). We need discardfunc() above
* because HEADER will dump the headers to stdout
* without it.
*/
curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 1L);
curl_easy_setopt(curlhandle, CURLOPT_HEADER, 1L);
assuming the comment is correct, I would expect the option CURLOPT_HEADER to be set to 0L instead.
I tried it as well but the behavior is the same described above.
Update
Just discovered on github that the above behavior is by design, because the SFTP protocol does not support the HEADER concept, so my question is, how can I use libcurl to retrieve the remote file size?
After several reading and interaction with curl mainteiner I solved the issue. A fully working example has been contributed to the curl project and kindly accepted. Here the details: https://curl.haxx.se/libcurl/c/sftpuploadresume.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With