使用SFTP协议使用Haskell的curl包上传文件的正确方法是什么?

时间:2013-07-26 16:19:38

标签: haskell libcurl

我尝试过使用Hackage的curl包通过SFTP上传文件的各种方法,到目前为止所有这些都会产生以下错误:

* 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

我在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)
[…]

我已验证网址,用户名和密码是否正确。此外,我还尝试使用SSHAuthPassword身份验证类型选项,并使用CurlUserNameCurlUserPassword设置用户名和密码。

从命令行执行curl

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

则成功

* 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

操作系统和库的版本如下:

$ 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 

我无法控制并且对我正在连接的服务器没有任何影响,因此切换到ssh-agent不是一种选择。

0 个答案:

没有答案