4

我已经尝试了各种方法来使用来自 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)
[…]

我已验证 URL、用户名和密码是否正确。此外,我还尝试使用auth type 选项,并使用andSSHAuthPassword设置用户名和密码。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 不是一种选择。

4

0 回答 0