如何让wget在发送USER命令前先发送AUTH TLS以使用FTPS下载文件?
问题描述
我尝试使用wget从FTP服务器下载文件,执行命令:
wget --debug --no-passive-ftp --ftp-user=user --ftp-password=password ftp://server/file.gz file.gz
得到如下响应:
220 Private FTP server Logging in as xxx ... --> USER xxx 331 Non-anonymous sessions must use encryption. --> PASS xxx Error in server response, closing control connection.
我可通过FileZilla正常连接并下载该服务器文件,其日志显示会先发送AUTH TLS建立TLS连接,再执行USER和PASS命令:
Response: 220 Private FTP server Command: AUTH TLS Response: 234 Proceed with negotiation. Status: Initializing TLS... Status: Verifying certificate... Status: TLS connection established. Command: USER xxx Response: 331 Please specify the password. Command: PASS ******************
但下载任务需在无法使用FileZilla的远程服务器执行,请问如何让wget在发送USER命令前先发送AUTH TLS命令?
解决方案
wget默认不会主动发起FTP的TLS加密握手,你需要添加--ftp-ssl参数,强制wget在发送USER命令前先执行AUTH TLS加密流程。如果需要同时加密数据传输通道,还可以搭配--ftp-ssl-all参数。
修改后的完整命令如下:
wget --debug --no-passive-ftp --ftp-ssl --ftp-user=user --ftp-password=password ftp://server/file.gz file.gz
添加--ftp-ssl后,wget会先发送AUTH TLS命令,完成TLS握手并建立加密连接后,再执行USER和PASS登录操作,和FileZilla的行为完全一致,即可满足服务器对加密登录的要求。
内容的提问来源于stack exchange,提问作者Piotr
相关产品推荐
相关产品推荐

