LibCurl SFTP获取完整的文件列表

时间:2016-02-07 11:24:42

标签: list directory sftp libcurl

我需要使用libcurl从2台服务器(ftp和sftp)获取完整的文件列表。

Libcurl信息:

System: Windows 7;
Wrapper: SourcePawn;
Version: libcurl/7.23.1 OpenSSL/0.9.8r zlib/1.2.5 libssh2/1.3.0;
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp.

关键是,我的代码返回ftp服务器的完整文件列表,但不是sftp。对于sftp服务器,我只得到一个(第一行)。

这是我的代码:

public RequestFileList()
{   
    new Handle:curl = curl_easy_init();
    if(curl != INVALID_HANDLE)
    {
        LogMessage("RequestFileList");

        CURL_DEFAULT_OPT(curl);


        curl_easy_setopt_function(curl, CURLOPT_WRITEFUNCTION, GetFileList);
        curl_easy_setopt_string(curl, CURLOPT_URL, "sftp://xxxxx:5000/");
        curl_easy_setopt_string(curl, CURLOPT_USERPWD, "xxx:xxx");
        curl_easy_setopt_int(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
        curl_easy_setopt_int(curl, CURLOPT_VERBOSE, 1);
        curl_easy_perform_thread(curl, onCompleteFilelist, 1);
    }
}
public GetFileList(Handle:hndl, const String:buffer[], const bytes, const nmemb)
{

    LogMessage("%s %i %i", buffer, bytes, nmemb);
}

输出:

drwxr-xr-x   11 root     root            0 Mar 27  2014 sys
 1 60

如果我用cmd执行它:

curl -k -u xxx:xxx sftp://xxxx:5000/

我获得完整的文件列表:

drwxr-xr-x   11 root     root            0 Mar 27  2014 sys
drwx------    2 root     root        16384 Jul 30  2009 lost+found
drwxr-xr-x   22 root     root         4096 Dec 31  2013 work
drwxr-xr-x    2 root     root         4096 Jul 30  2009 plugin

如何获取完整文件列表?

这是完整的日志:

* About to connect() to xxxxxxxxxxx port 5000 (#0)
*   Trying xxx.xxx.xxx.xxx... 
* connected
* SSH authentication methods available: publickey,gssapi-keyex,gssapi-with-mic,password
* Using ssh public key file id_dsa.pub
* Using ssh private key file id_dsa
* SSH public key authentication failed: Unable to open public key file
* Initialized password authentication
* Authentication complete
L 02/07/2016 - 13:57:36: [pl.smx] STR - drwxr-xr-x   11 root     root            0 Mar 27  2014 sys
 1 60
* Connection #0 to host xxxxxxxxxxxxxxxx left intact
* Closing connection #0

1 个答案:

答案 0 :(得分:2)

您的write callback返回错误的值,因此libcurl会停在那里。