cURL / Mailing Lists / curl-library / Single Mail

curl-library

libcurl takes long time to connect to CoreFTP's SFTP service

From: Xu, Qiang (FXSGSC) <Qiang.Xu_at_fujixerox.com>
Date: Wed, 10 Feb 2010 19:13:18 +0800

Hi, list:

I am using libcurl (together with libssh2) to do SFTP transfer, using SFTP service provided by CoreFTP. Yet, I found it costs a lot of time for each session.
===================================
/* source code */
#include <stdio.h>
#include <time.h>
#include <curl/curl.h>

int main(int argc, char *argv[])
{
  CURLcode ret;
  CURL *hnd = curl_easy_init();

  curl_easy_setopt(hnd, CURLOPT_URL, "sftp://13.xxx.xxx.xxx/");
  curl_easy_setopt(hnd, CURLOPT_USERPWD, "xxx:xxx");
  curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1);

  ret = curl_easy_perform(hnd);

  curl_easy_cleanup(hnd);
  return (int)ret;
}

/* result */
qxu_at_durian(pts/3):~/opensrc/curl-7.19.6/example[154]$ date
Wed Feb 10 18:31:26 SGT 2010
qxu_at_durian(pts/3):~/opensrc/curl-7.19.6/example[155]$ ./sftp_coreftp
* About to connect() to 13.121.8.242 port 22 (#0)
* Trying 13.121.8.242... * connected
* Connected to 13.121.8.242 (13.121.8.242) port 22 (#0)
* SSH authentication methods available: password
* Initialized password authentication
* Authentication complete
drw-rw-rw 1 root root 0 Feb 10 05:24 .
drw-rw-rw 1 root root 0 Feb 10 05:24 ..
drw-rw-rw 1 root root 0 Feb 9 14:32 Desktop
-rw-rw-rw 1 root root 15271 Feb 10 02:08 DOC.PDF
-rw-rw-rw 1 root root 3028 Feb 10 02:08 DOC.XST
-rw-rw-rw 1 root root 15642 Feb 10 02:13 DOC000.PDF
-rw-rw-rw 1 root root 3031 Feb 10 02:13 DOC000.XST
-rw-rw-rw 1 root root 43623 Feb 10 02:25 DOC001.PDF
-rw-rw-rw 1 root root 3031 Feb 10 02:25 DOC001.XST
drw-rw-rw 1 root root 0 Feb 10 05:03 DOC002.LCK
-rw-rw-rw 1 root root 16012 Feb 10 05:13 DOC002.PDF
-rw-rw-rw 1 root root 3031 Feb 10 05:24 DOC002.XST
drw-rw-rw 1 root root 0 Feb 8 10:47 Favorites
drw-rw-rw 1 root root 0 Feb 8 10:47 My Documents
drw-rw-rw 1 root root 0 Feb 9 17:02 Scans
drw-rw-rw 1 root root 0 Apr 9 05:13 Start Menu
* Connection #0 to host 13.xxx.xxx.xxx left intact /* output till this line appears very quickly, but the following output takes more than 10 mins to appear */
* Failed to stop libssh2 sftp subsystem
* Closing connection #0
qxu_at_durian(pts/3):~/opensrc/curl-7.19.6/example[156]$ date
Wed Feb 10 18:41:52 SGT 2010
===================================
To my surprise, it takes more than 10 mins for a simple connection. I don't know if the message "Failed to stop libssh2 sftp subsystem" is implying something.

In contrast, when SFTP service is provided by OpenSSH, the session is finished much more quickly. Source code is nearly the same, I just stopped CoreFTP service in the Windows XP workstation, and did a "net start opensshd" to start the service. Of course, SSHWindows must be installed beforehand.
===================================
xu_at_durian(pts/3):~/opensrc/curl-7.19.6/example[162]$ date
Wed Feb 10 18:46:47 SGT 2010
qxu_at_durian(pts/3):~/opensrc/curl-7.19.6/example[163]$ ./sftp_openssh
* About to connect() to 13.121.8.242 port 22 (#0)
* Trying 13.121.8.242... * connected
* Connected to 13.121.8.242 (13.121.8.242) port 22 (#0)
* SSH authentication methods available: publickey,password,keyboard-interactive
* Using ssh public key file /home/qxu/.ssh/id_dsa.pub
* Using ssh private key file /home/qxu/.ssh/id_dsa
* SSH public key authentication failed: Unable to open public key file
* Initialized password authentication
* Authentication complete
drwx------ 8 Administrator None 0 Feb 8 10:20 .
drwx------ 8 Administrator None 0 Feb 8 10:20 ..
drwx------ 2 Administrator None 0 Feb 8 10:19 bin
drwx------ 2 Administrator None 0 Feb 8 10:19 docs
drwx------ 2 Administrator None 0 Feb 8 10:28 etc
drwx------ 2 Administrator None 0 Feb 8 10:19 tmp
-rwx------ 1 Administrator None 85619 Feb 8 10:20 uninstall.exe
drwx------ 4 Administrator None 0 Feb 8 10:19 usr
drwx------ 4 Administrator None 0 Feb 8 10:19 var
* Connection #0 to host 13.xxx.xxx.xxx left intact
* Closing connection #0
qxu_at_durian(pts/3):~/opensrc/curl-7.19.6/example[164]$ date
Wed Feb 10 18:47:01 SGT 2010
===================================
This session only used less than 20 seconds.

Is it a server problem? I am not sure, coz FileZilla can connect to CoreFTP SFTP server rather quickly. Hope someone in this list can shed some light on this problem.

Thanks,
Xu Qiang
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-02-10