Windows ftp 客户端出现“500 端口命令无效”错误

'500 Port command invalid' error in Windows ftp client

我创建了一个脚本,用于从 FTP 服务器下载文件,使用 VBA 启动脚本。我可以连接到服务器并导航到正确的目录,但是当我获取文件时,我收到消息:

500 Port command invalid

我已经尽可能多地调整了代码,但我对端口的了解不够,或者 FTP 不知道我需要更改什么。

VBA代码:

Dim FTPcommand As String
Dim wsh As Object

FTPcommand = "ftp -n -s:" & Chr(34) & "C:\path\to\FTP_commands.txt" & Chr(34)
Set wsh = CreateObject("WScript.Shell")
wsh.Run FTPcommand, 5, True

脚本:

open ftp.blahblahbah.bl
user username password
lcd C:\Users\me\Documents\location
cd /specific location/
get "file.xlsx"

我希望文件下载但收到以下消息(在脚本登录并成功导航到文件路径后):

ftp> open ftp.address.com
Connected to ftp.address.com
220 Welcome to address.com
ftp> user USERNAME PASSWORD
---> USER USERNAME
331 User USERNAME, password please
---> PASS PASSWORD
230 Password Ok, User logged in
ftp lcd C:\Users\joe\Documents
Local directory now C:\Users\joe\Documents.
ftp> cd /location/
--->CWD /location/
250 Change directory ok
ftp get "file.xlsx"
---> PORT 192.168.1.121.242.113
500 Port command invalid
RETR file.xlsx
425 Unable to open the data connection

---> PORT 192.168.1.121.242.113
500 Port command invalid

看起来 ftp 正在向另一个网络中的 FTP 服务器发送内部 IP 地址。服务器无法连接到该 IP 地址。我不认为,有一种方法可以用 ftp 解决它。您的网络 firewall/NAT 可以通过在 PORT 命令中转换 IP 地址来解决它。


或者您需要使用不同的 FTP 客户端,它支持 FTP 被动模式。

您可以使用 WinSCP FTP client. There's a guide to converting Windows ftp script to WinSCP.

以下 WinSCP 代码等同于您的:

Dim FTPcommand As String
Dim wsh As Object

FTPcommand = """C:\Path\To\winscp.com"" /ini=nul /script=""C:\Path\To\FTP_commands.txt"""
Set wsh = CreateObject("WScript.Shell")
wsh.Run FTPcommand, 5, True

剧本:

open ftp://username:password@ftp.blahblahbah.bl/
lcd C:\Users\me\Documents\location
cd /specific location/
get "file.xlsx"
exit

(我是WinSCP的作者)