4

I've tried a variety of things to upload a file via SFTP using the curl package from Hackage, so far all of them produce the following error:

* About to connect() to [redacted] port 22 (#0)
*   Trying [redacted]... * connected
* Connected to [redacted] ([redacted]) port 22 (#0)
* Failure establishing ssh session
* Closing connection #0
* Failed initialization
ERROR: CurlFailedInit

I'm setting the following options in Haskell:

[…]
Curl.setopt curlLib (Curl.CurlFailOnError True)
Curl.setDefaultSSLOpts curlLib url  -- not necessary for sftp:// protocol, but shouldn't be a problem
Curl.setopt curlLib (Curl.CurlURL url)
Curl.setopt curlLib (Curl.CurlSSLVerifyHost 0)
Curl.setopt curlLib (Curl.CurlSSLVerifyPeer False)
Curl.setopt curlLib (Curl.CurlSSHAuthTypes [Curl.SSHAuthAny])
Curl.setopt curlLib (Curl.CurlUserPwd "user:password")
Curl.setopt curlLib (Curl.CurlUpload True)
[…]

I have verified that the URL, username, and password are correct. Additionally, I've also tried using the SSHAuthPassword auth type option, and setting the username and password with CurlUserName and CurlUserPassword.

Executing curl from the command line

$ curl -vvv --upload-file test.txt --user 'user:password' "sftp://[redacted]/~/test.txt"

Succeeds

* About to connect() to [redacted] port 22 (#0)
*   Trying [redacted]... connected
* Connected to [redacted] ([redacted]) port 22 (#0)
* Failed to read known hosts from [redacted]
* SSH host check: 0, key: [redacted]        
* SSH authentication methods available: gssapi-keyex,gssapi-with-mic,publickey,password,keyboard-interactive
* Using ssh public key file [redacted]
* Using ssh private key file [redacted]
* SSH public key authentication failed: Unable to open public key file
* Initialized password authentication
* Authentication complete
[…]
* Closing connection #0

The versions of the OS and libraries are as follows:

$ uname -r
2.6.32-131.12.1.el6.x86_64
$ cat /etc/redhat-release
Red Hat Enterprise Linux Workstation release 6.1 (Santiago)
$ cabal info curl
[…]
Latest version installed: 1.3.8
[…]
$ curl --version
curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.3.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp 
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz 

I don't control and have no influence over the server I'm connecting to, so switching to ssh-agent is not an option.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.