windows 我的 FTP 批处理脚本卡在“200 PORT 命令成功”并且没有将文件上传到服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30591387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:06:23  来源:igfitidea点击:

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

windowsbatch-fileftpautomation

提问by Idan E

I've tried everything I found in Google results about

我已经尝试了在 Google 结果中找到的所有内容

200 PORT command successful

200 PORT 命令成功

but nothing has helped.

但没有任何帮助。

Can anyone assist to solve this issue please?

任何人都可以帮助解决这个问题吗?

The code of "runScript.bat:

“runScript.bat”的代码:

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

The code of "fileup.bat:

“fileup.bat”的代码:

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

The console log:

控制台日志:

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

The error regarding WinSCP (for Martin)":

关于 WinSCP 的错误(对于 Martin)”:

C:\Users\idan>cd c:\automation\

c:\automation>runFTP.bat

c:\automation>winscp.com /command     "open ftp://user:[email protected]/"     "cd /public_html/reports/"     "lcd C:\automation\tests\HtmlRepo
rter"     "put *"     "exit"
'winscp.com' is not recognized as an internal or external command,
operable program or batch file.

c:\automation>

回答by Martin Prikryl

This looks like a typical problem with the FTP active mode. The server cannot connect back to your machine to establish a data transfer connection.

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

That typically happens as nowadays most client machines are behind a firewall or NAT or both, what prevents the FTP active mode from working. To make the active mode working you need to open your firewall (not recommended) and/or configure NAT routing rules.

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

See my article on FTP modes and configuring network for the active mode.

请参阅我关于FTP 模式和为活动模式配置网络的文章。



Or you use the passive FTP mode. The Windows ftp.execlient does not support the passive mode though, what makes it pretty useless nowadays.

或者您使用被动 FTP 模式。Windowsftp.exe客户端虽然不支持被动模式,但现在它变得毫无用处。

So you need to use another command-line FTP client. A majority of FTP clients do support the passive mode.

所以你需要使用另一个命令行 FTP 客户端。大多数 FTP 客户端确实支持被动模式。

For example with WinSCPyour runScript.batwould be like:

例如,使用WinSCP,runScript.bat会像这样:

winscp.com /command ^
    "open ftp://username:[email protected]/" ^
    "cd /public_html/reports/" ^
    "lcd C:\automation\tests\HtmlReporter" ^
    "put *" ^
    "exit"

Note that WinSCP defaults to the passive mode.

请注意,WinSCP 默认为被动模式。

For details see WinSCP guides for:

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

(I'm the author of WinSCP)

(我是 WinSCP 的作者)

回答by Sergei Tche

I had exactly the same problem ("200 PORT command successful" stuck on the screen forever), and I was able to solve it.

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

First of all, there are lot of posts on the Internet saying that Windows ftp.exe doesn't support passive mode. This is not true:

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

ftp> quote pasv

ftp> 引用 pasv

227 Entering Passive Mode

227 进入被动模式

In my case I had a Windows 2012 R2 server with a real IP. Switching to the passive mode didn't solve the problem, I was still stuck at "200 PORT command successful". At the same time WinSCP worked fine. The solution was to create an inbound firewall rule which allowed external connections from FTP server to the local ftp.exe.

就我而言,我有一台带有真实 IP 的 Windows 2012 R2 服务器。切换到被动模式并没有解决问题,我仍然卡在“200 PORT命令成功”。同时 WinSCP 工作正常。解决方案是创建一个入站防火墙规则,允许从 FTP 服务器到本地 ftp.exe 的外部连接。