我有一个非常旧的shell脚本在生产机器上运行,我刚刚从客户那里获得了访问权限,我的工作是将它转换为等效的curl
。这个脚本非常简单,它所做的只是将文件从远程FTP下载到本地文件系统:
lftp -u Username,'pass' xxx.xxx.xx.xx << !
echo 'Connected'
get dir/file.csv
exit
!
首先,用卷曲来代替它可能吗?对我来说,这看起来像是一个简单的FTP获取脚本,但我可能不知道使用curl下载FTP文件的任何细微差别。
其次,以下是我迄今为止根据在互联网上发现的十几个线程所做的尝试,但都不起作用:
curl ftp://Username:pass@xxx.xxx.xx.xx/dir/file.csv --ftp-ssl
#=> curl: (67) Access denied: 550
curl ftps://Username:pass@xxx.xxx.xx.xx/dir/file.csv --ftp-ssl
#=> curl: (67) Access denied: 550
curl -P - --insecure "ftp://xxx.xxx.xx.xx/dir/file.csv" --user "Username:pass" --ftp-ssl
#=> curl: (67) Access denied: 550
编辑:添加-v
后,我意识到证书有一些问题,所以我添加了--insecure
标志,现在它告诉登录不正确,而我100%确定登录和密码都是正确的。输出:
* Trying xxx.xxx.xx.xx...
* TCP_NODELAY set
* Connected to xxx.xxx.xx.xx (xxx.xxx.xx.xx) port 21 (#0)
< 220 NASFTPD Turbo station 1.3.5a Server (ProFTPD)
> AUTH SSL
< 234 AUTH SSL successful
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
* subject: C=TW; ST=xxx; L=xxx; O=xxx, Inc.; OU=xxx; CN=xxx; emailAddress=xxx
* start date: Mar 11 10:45:27 2016 GMT
* expire date: Mar 9 10:45:27 2026 GMT
* issuer: C=TW; ST=xxx; L=Taipei; O=xxx, Inc.; OU=QTS; CN=xxx; emailAddress=xxx
* SSL certificate verify result: self signed certificate (18), continuing anyway.
> USER Username
< 331 Password required for Username
> PASS s
< 530 Login incorrect.
* Access denied: 530
* Closing connection 0
* TLSv1.2 (OUT), TLS alert, Client hello (1):
curl: (67) Access denied: 530
此问题是由于密码包含$
字符导致密码解析不正常,并且只使用了密码的第一个字母(下一个字母是美元符号(。将密码包装在单引号内为我解决了这个问题。