我的 FTP 批处理脚本卡在“200 PORT 命令成功”上,无法将文件上传到服务器

My FTP batch script is stuck on "200 PORT command successful" and doesn't upload the files to server

我已经尝试了在 Google 结果中找到的关于

的所有内容

200 PORT command successful

但没有任何帮助。

有人可以帮忙解决这个问题吗?

"runScript.bat的代码:

ftp -s:"C:\automation\fileup.bat" myserver.com

"fileup.bat的代码:

username
password
ascii
cd "/public_html/reports/"
lcd "C:\automation\tests\HtmlReporter"
prompt
mput *
disconnect
close
bye

控制台日志:

C:\automation>ftp -s:"C:\automation\fileup.bat" myserver.com
Connected to myserver.com.
220---------- Welcome to Pure-FTPd [privsep] ----------
220-You are user number 7 of 500 allowed.
220-Local time is now 04:40. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
User (server26.000webhost.com:(none)):
331 User username OK. Password required

230-OK. Current restricted directory is /
230-449 files used (4%) - authorized: 10000 files
230 16742 Kbytes used (1%) - authorized: 1536000 Kb
ftp> ascii
200 TYPE is now ASCII
ftp> cd "/public_html/reports/"
250 OK. Current directory is /public_html/reports
ftp> lcd "C:\automation\tests\HtmlReporter"
Local directory now C:\automation\tests\HtmlReporter.
ftp> prompt
Interactive mode Off .
ftp> mput *
200 PORT command successful

这看起来像是 FTP 活动模式的典型问题。服务器无法连接回您的计算机以建立数据传输连接。

这通常会发生,因为现在大多数客户端机器都在防火墙或 NAT 或两者之后,这阻止了 FTP 活动模式的工作。要使主动模式工作,您需要打开防火墙(不推荐)and/or 配置 NAT 路由规则。

请参阅我在 FTP modes and configuring network for the active mode 上的文章。


或者你使用被动FTP模式。 Windows ftp.exe 客户端虽然不支持被动模式,但现在它几乎没用了。

因此您需要使用另一个命令行 FTP 客户端。大多数 FTP 客户端支持被动模式。

例如 WinSCP 你的 runScript.bat 会像:

winscp.com /command ^
    "open ftp://username:password@myserver.com/" ^
    "cd /public_html/reports/" ^
    "lcd C:\automation\tests\HtmlReporter" ^
    "put *" ^
    "exit"

注意WinSCP默认为被动模式。

有关详细信息,请参阅 WinSCP 指南:

(我是WinSCP的作者)

我遇到了完全相同的问题(“200 PORT 命令成功”永远停留在屏幕上),我能够解决它。

首先,网上有很多帖子说Windows ftp.exe不支持被动模式。这不是真的:

ftp> 引用 pasv

227进入被动模式

在我的例子中,我有一个 Windows 2012 R2 服务器和一个真实的 IP。切换到被动模式并没有解决问题,我仍然卡在“200 PORT 命令成功”。同时 WinSCP 运行良好。解决方案是创建一个入站防火墙规则,允许从 FTP 服务器到本地 ftp.exe.

的外部连接