I am trying to set up curl to fetch a file from an SFTP server on my Fedora box. The command I am running is:

curl -s -S -u 'user:pass' -k 'sftp://aserver.com/afile' -o afile 2>&1

The error I am getting is:

afile: curl: (2) Failure initializing sftp session: Unable to send SSH_FXP_INIT

I can connect to the server using sftp with no errors.

Has anyone seen this before and has a workaround? Perhaps it's some curl parameter I am not setting?

Here's the output of curl -v

curl 7.20.1 (x86_64-redhat-linux-gnu) libcurl/7.20.1 NSS/3.12.8.0 zlib/1.2.3 libidn/1.16 libssh2/1.2.4
Protocols: dict file ftp ftps http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

Here's the trace from curl:

* About to connect() to aserver.com port 22 (#0)
*   Trying 123.123.132.123...   
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0 connected
* Connected to aserver.com (123.123.123.123) port 22 (#0)
* SSH authentication methods available: password,publickey,keyboard-interactive
* Using ssh public key file /home/user/.ssh/id_dsa.pub
* Using ssh private key file /home/user/.ssh/id_dsa
* SSH public key authentication failed: Unable to open public key file
* Initialized password authentication
* Authentication complete
* Failure initializing sftp session: Unable to send SSH_FXP_INIT
* Closing connection #0

curl: (2) Failure initializing sftp session: Unable to send SSH_FXP_INIT

Follow up: I gave up on curl after days of trying to get it to work. Ended up writing a fetching utility in Java using a third-party FTP/SFTP/FTPS library. Sad to say that this took me less time than I spent troubleshooting curl and the OS libraries.

link|improve this question
Try adding --verbose – grawity Mar 17 '11 at 16:49
Added. I am afraid it's not very helpful. – Oleg Barshay Mar 17 '11 at 17:11
Just to be clear about it: You are able to connect to the sftp server with curl -s -S -k -u user:pass sftp://address.com/ but you can't download the file? – p.vitzliputzli Mar 17 '11 at 17:20
Hard to say whether the problem occurs at connect time or during the download. From the trace log it looks like a connection is being established but the SSH session is not. There are no issues using command like sftp. – Oleg Barshay Mar 17 '11 at 17:41
@Oleg: The SSH session is okay (it even passes authentication); only the SFTP subsystem is not working. Are you able to connect using the sftp client? Does the server's syslog show any errors? (Also worth trying: stop the SSH server and run sshd -rddd, for one-shot debug mode, then try curl again.) – grawity Mar 17 '11 at 18:22
show 2 more comments
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.