cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Unnecessary delay downloading multiple files (via SFTP)?

From: Patrik Thunström <patrik.thunstrom_at_bassetlabs.com>
Date: Wed, 18 Feb 2009 10:20:43 +0100

Daniel Stenberg wrote:
> Nope. The select() or poll() that is called is level-trigged and not
> edge-trigged so if the situation remains it would return.
>
> I think the problem is more related to libssh2 internals and perhaps
> it somehow returns EAGAIN for something that it shouldn't and when
> called again it can comsume already buffered data even though nothing
> happened on the socket, or similar. Did you try enabling libssh2
> debug/trace details yet?
>
> Can you provide a small but working source code example showing this
> wait?
Yes, no problem, attached to this email is a test program... As might be
noticed from it, which wasn't mentioned until now, I'm running this on
win32. The code here is based on the small test program listed in Andrei
Jakab's guide on how to build libcurl with SSH support with visual
studio 2008, as that was my starting point for trying out libcurl.

The actual code that performs anything is isolated in it's own function,
so it should be easy to move this out and remove the windows
dependencies. It's so small it shouldn't be any problems getting a grasp
of, it simply needs changing a variable to the address of a existing
SFTP server, a path to possible files, and the for-loop + sprintf part
might be looked at to decide which files to get.

As for the libssh2 debug/trace details, the answer's no, I haven't
looked into that yet.

Best Regards
Patrik Thunström

#include <tchar.h>
#include <conio.h>
#include <curl/curl.h>
#include <windows.h>

void SSHUpload()
{
        char strBuffer[1024];
        static char* host = "<enter-your-host>";
        static char* path = "/home/user/testdata";
        CURL * hCurl;
        CURLcode ccCurlResult = CURL_LAST;
        
        ccCurlResult = curl_global_init(CURL_GLOBAL_WIN32);

        if(ccCurlResult == 0)
        {
                hCurl = curl_easy_init();

                if(hCurl)
                {
                        curl_easy_setopt(hCurl, CURLOPT_VERBOSE, TRUE);
                        curl_easy_setopt(hCurl, CURLOPT_PORT, 22);
                        curl_easy_setopt(hCurl, CURLOPT_USERPWD, "user:user");
                        curl_easy_setopt(hCurl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_ANY);
                                
                        for(int i = 0; i < 12; i++) {
                                sprintf(strBuffer, "sftp://%s%s/%d.txt", host, path, i+1);
                                ccCurlResult = curl_easy_setopt(hCurl, CURLOPT_URL, strBuffer);
                                ccCurlResult = curl_easy_perform(hCurl);
                        }
                                
                        curl_easy_cleanup(hCurl);
                }
        }

        curl_global_cleanup();
}

int _tmain(int argc, _TCHAR* argv[])
{
        SSHUpload();
        printf("Press any key to continue...");
        _getch();
        return 0;
}
Received on 2009-02-18