获取“无法打开与端口xxxx的数据连接".从Windows批处理文件将文件上传到FTP时 [英] Getting "Could not open data connection to port xxxx" when uploading file to FTP from Windows batch file

查看:91
本文介绍了获取“无法打开与端口xxxx的数据连接".从Windows批处理文件将文件上传到FTP时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用批处理文件将文本文件上传到FTP服务器.它成功登录并显示

I am trying to upload a text file to FTP server using a batch file. It logins successfully and shows

端口命令发送成功

Port command sent successfully

但随后显示

无法打开与端口xxxx的数据连接
连接超时

Could not open data connection to port xxxx
Connection timed out

这是批处理脚本:

@echo off

for %%A in (*.csv) do set latest=%%A 
echo Latest file is %latest%  

echo MYUSERNAME> upload.txt 
echo MYPASSWORD>> upload.txt 
echo asc>>upload.txt 
echo put %latest% s.txt>> upload.txt 
echo quit >> upload.txt  

ftp -s:upload.txt server58.hostinger.in

推荐答案

这似乎是FTP活动模式的典型问题.服务器无法连接回您的计算机以建立数据传输连接.

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

这种情况通常发生,因为当今大多数客户端计算机都位于防火墙或NAT或两者之后,这导致FTP主动模式无法正常工作.要使活动模式正常工作,您需要打开防火墙(不推荐)和/或配置NAT路由规则.

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.

请参见 FTP模式和将网络配置为活动模式的文章.

或者您使用被动FTP模式.但是,Windows ftp.exe客户端不支持被动模式,这使它在今天变得毫无用处.

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

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

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

例如,使用 WinSCP ,您的批处理文件将是:

For example with WinSCP your batch file would be like:

@echo off

for %%A in (*.csv) do set latest=%%A 
echo Latest file is %latest%

winscp.com /command ^
    "open ftp://MYUSERNAME:MYPASSWORD@server58.hostinger.in/" ^
    "put -transfer=ascii %latest% s.txt" ^
    "exit"

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

Note that WinSCP defaults to the passive mode.

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

For details see WinSCP guides for:

  • Automating file transfers to FTP server
  • Converting Windows FTP script to WinSCP script

(我是WinSCP的作者)

这篇关于获取“无法打开与端口xxxx的数据连接".从Windows批处理文件将文件上传到FTP时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆