如何在 Windows 命令提示符下使用被动 FTP 模式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18643542/
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-09 10:51:10  来源:igfitidea点击:

How to use passive FTP mode in Windows command prompt?

windowsftpcommand-prompt

提问by Martin Prikryl

In Ubuntu ftp -pfor passive mode works fine.

在 Ubuntu 中ftp -p,被动模式工作正常。

How do I do the same in Windows?

我如何在 Windows 中做同样的事情?

I tried with quote pasvbut I am getting following error:

我尝试过,quote pasv但出现以下错误:

230 OK. Current restricted directory is /
ftp> quote pasv 
227 Entering Passive Mode (31,170,167,221,116,239)    
ftp> cd os    
250 OK. Current directory is /os    
ftp> dir    
500 I won't open a connection to 10.23.16.248 (only to 113.193.128.177)    
425 No data connection    
ftp>

My firewall is disabled.

我的防火墙被禁用了。

回答by Martin Prikryl

The Windows FTP command-line client (ftp.exe) does not support the passive mode, on any version of Windows. It makes it pretty useless nowadays due to ubiquitous firewalls and NATs.

Windows FTP 命令行客户端 ( ftp.exe) 在任何版本的 Windows 上都不支持被动模式。由于无处不在的防火墙和 NAT,它现在变得非常无用。

Using the quote pasvwon't help. It switches only the serverto the passive mode, but not the client.

使用quote pasv将无济于事。它只将服务器切换到被动模式,而不是客户端



Use any thirdparty Windows FTP command-line client instead. Most other support the passive mode.

请改用任何第三方 Windows FTP 命令行客户端。大多数其他支持被动模式。

For example WinSCPdefaults to the passive mode and there's a guide available for converting Windows FTP script to WinSCP script.

例如WinSCP默认为被动模式,并且有一个指南可用于将Windows FTP 脚本转换为 WinSCP 脚本

(I'm the author of WinSCP)

(我是 WinSCP 的作者)

回答by transilvlad

Windows does not actually support passive mode.

Windows 实际上并不支持被动模式。

You can send the command to the server in three different ways but that will not enable passive mode on the Windows client end.

您可以通过三种不同的方式将命令发送到服务器,但这不会在 Windows 客户端启用被动模式。

Those arguments are for sending various commands and pasvis not something that Microsoft thought of when they wrote it.

这些参数用于发送各种命令,pasv并不是微软在编写它时想到的。

You will have to find a 3rd party software like WinSCP that supports command line usage and use that instead of the Windows native one.

您必须找到像 WinSCP 这样支持命令行使用的 3rd 方软件,并使用它而不是 Windows 原生软件。

回答by Hammad

Although this doesnt answer the question directly about command line, but from Windows OS, use the Windows Explorer ftp://username@server

虽然这并没有直接回答有关命令行的问题,但是从 Windows 操作系统,使用 Windows 资源管理器ftp://username@server

this will use Passive Mode by default

这将默认使用被动模式

For command line, active mode is the default

对于命令行,活动模式是默认的

回答by Bruce Peterson

The quote PASVcommand is not a command to the ftp.exeprogram, it is a command to the FTP server requesting a high order port for data transfer. A passive transfer is one in which the FTP data over these high order ports while control is maintained in the lower ports.

quote PASV命令不是对ftp.exe程序的命令,而是对 FTP 服务器请求数据传输的高阶端口的命令。被动传输是这样一种传输,其中 FTP 数据通过这些高阶端口,而控制权则保留在较低的端口中。

The windows ftp.exeprogram can be used to send the FTP server commands to make a passive data transfer between two FTP servers. A standard windows installation will not, and probably should not, have FTP server service running as an endpoint for passive transfers. So if passive transfers are needed with a standard windows box, a solution other than ftp.exeis necessary as FTPing to localhost as one of the connections won't work in most windows environments.

Windowsftp.exe程序可用于发送 FTP 服务器命令,以在两个 FTP 服务器之间进行被动数据传输。标准的 Windows 安装不会,也可能不应该将 FTP 服务器服务作为被动传输的端点运行。因此,如果需要使用标准 Windows 框进行被动传输,则需要其他解决方案,ftp.exe因为 FTP 到 localhost 作为连接之一在大多数 Windows 环境中不起作用。

You can effect a passive FTP transfer between two different hosts (but not two connections on the same host) as follows:

您可以在两个不同的主机(但不是同一主机上的两个连接)之间实现被动 FTP 传输,如下所示:

Open up two prompts, use one to ftp.execonnect to your source FTP server and one to ftp.execonnect to your destination FTP server.

打开两个提示,一个ftp.exe连接到你的源FTP服务器,一个ftp.exe连接到你的目标FTP服务器。

Now establish a passive connection between the servers using the raw commands PASV and PORT. The quote PASVcommand will respond with an IP/port in ellipsis. Use that data for the quote PORT <data>command. Your passive link is now established assuming that firewalls haven't blocked one or more of the four ports (2 for FTP control, 2 for FTP data)

现在使用原始命令 PASV 和 PORT 在服务器之间建立被动连接。该quote PASV命令将使用省略号中的 IP/端口进行响应。将该数据用于quote PORT <data>命令。假设防火墙没有阻止四个端口中的一个或多个(2 个用于 FTP 控制,2 个用于 FTP 数据),您的被动链接现在已建立

Next start receive of data with the quote STOR <filename>command to the receiving FTP server then send the control command quote RETR <filename>to the source FTP server.

接下来用quote STOR <filename>命令开始接收数据到接收 FTP 服务器,然后将控制命令发送quote RETR <filename>到源 FTP 服务器。

so for me:

所以对我来说:

client 1
> ftp.exe server1
ftp> quote PASV
227 Entering Passive Mode (10,0,3,1,54,161)

client 2 
> ftp.exe server2
ftp> quote PORT 10,0,3,1,54,54,161
ftp> quote STOR myFile

client 1
ftp> quote RETR myFile

Cavet: I'm connecting to some old FTP servers YMMV

Cavet:我正在连接一些旧的 FTP 服务器 YMMV

回答by Whome

CURL client supports FTP protocol and works for passive mode. Get Download WITHOUT SSLversion and you don't need any openssl.dll libraries. Just one curl.exe command line application.
http://www.paehl.com/open_source/?CURL_7.35.0

CURL 客户端支持 FTP 协议,工作于被动模式。无需 SSL版本即可下载,您不需要任何 openssl.dll 库。只有一个 curl.exe 命令行应用程序。
http://www.paehl.com/open_source/?CURL_7.35.0

curl.exe -T c:\test\myfile.dat ftp://ftp.server.com/some/folder/myfile.dat --user myuser:mypwd

Another one is Putty psftp.exe but server key verification prompt requires a trick. This command line inputs NO for prompt meaning key is not stored in registry just this time being used. You need an external script file but sometimes its good if you copy multiple files up and down.
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

另一个是 Putty psftp.exe 但服务器密钥验证提示需要一个技巧。此命令行输入 NO 进行提示,表示此时正在使用的密钥未存储在注册表中。您需要一个外部脚本文件,但有时如果您上下复制多个文件,它会很好。
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

echo n | psftp.exe ftp.server.com -l myuser -pw mypwd -b script.txt

script.txt (any ftp command may be typed)

script.txt(可以输入任何 ftp 命令)

put "C:\test\myfile.dat" "/some/folder/myfile.dat"
quit

回答by JaeMann Yeh

If you are using Windows 10, install Windows Subsystem for Linux, WSL and Ubuntu.

如果您使用的是 Windows 10,请安装适用于 Linux、WSL 和 Ubuntu 的 Windows 子系统。

$ ftp 192.168.1.39
Connected to 192.168.1.39.
............
230 Logged in successfully
Remote system type is MSDOS.
ftp> passive
Passive mode on.
ftp> passive
Passive mode off.
ftp>

回答by Ashutosh Raj

This is a common problem . when we start the ftp connection only the external ip opens the port for pasv connection. but the ip behind the NAT doesn't open the connection so passive connection fails with PASV command

这是一个常见的问题。当我们启动 ftp 连接时,只有外部 ip 打开用于 pasv 连接的端口。但是 NAT 后面的 ip 没有打开连接,因此使用 PASV 命令进行被动连接失败

we need to specify that while opening the connection so open connection with

我们需要指定在打开连接时打开连接

ftp -p {host}

ftp -p {主机}

回答by Slav

For passive mode you need to use command "literal" ftp>literal PASV

对于被动模式,您需要使用命令“literal” ftp>literal PASV

回答by John O'Regan

According to this Egnyte article, Passive FTP is supported from Windows 8.1 onwards.

根据这篇Egnyte 文章,从 Windows 8.1 开始支持被动 FTP。

The Registry key:

注册表项:

"HKEY_CURRENT_USER\Software\Microsoft\FTP\Use PASV"

"HKEY_CURRENT_USER\Software\Microsoft\FTP\Use PASV"

should be set with the value: yes

应设置为以下值: yes

If you don't like poking around in the Registry, do the following:

如果您不喜欢在注册表中闲逛,请执行以下操作:

  1. Press WinKey+Rto open the Run dialog.
  2. Type inetcpl.cpland press Enter. The Internet Options dialog will open.
  3. Click on the Advanced tab.
  4. Make your way down to the Browsing secction of the tree view, and ensure the Use Passive FTP item is set to on.
  5. Click on the OK button.
  1. WinKey+R打开运行对话框。
  2. 键入inetcpl.cpl并按Enter。Internet 选项对话框将打开。
  3. 单击高级选项卡。
  4. 转到树视图的浏览部分,并确保将使用被动 FTP 项设置为打开。
  5. 单击确定按钮。

Every time you use ftp.exe, remember to pass the

每次使用时ftp.exe,记得通过

quote pasv

quote pasv

command immediately after logging in to a remote host.

登录远程主机后立即执行命令。

PS: Grant ftp.exeaccess to private networks if your Firewall complains.

PS:ftp.exe如果您的防火墙抱怨,则授予对私有网络的访问权限。

回答by Ron Arndt

FileZilla Works well. I Use FileZilla FTP Client "Manual Transfer" which supports Passive mode.

FileZilla 运行良好。我使用支持被动模式的 FileZilla FTP 客户端“手动传输”。

Example: Open FileZilla and Select "Transfer" >> "Manual Transfer" then within the Manual Transfer Window, perform the following:

示例:打开 FileZilla 并选择“传输”>>“手动传输”,然后在手动传输窗口中,执行以下操作:

  1. Confirm proper Download / Upload option is selected
  2. For Remote: Enter name of directory where the file to download is located
  3. For Remote: Enter the name of the file to be downloaded
  4. For Local: Browse to desired directory you want to download file to
  5. For Local: Enter a file name to save downloaded file As (use same file name as file to be downloaded unless you want to change it)
  6. Check-Box "Start transfer immediately" and Click "OK"
  7. Download should start momentarily
  8. Note: If you forgot to Check-Box "Start transfer immediately"... No Problem: just Right-Click on the file to be downloaded (within the Process Queue (file transfer queue) at the bottom of the FileZilla window pane and Select "Process Queue"
  9. Download process should begin momentarily
  10. Done
  1. 确认选择了正确的下载/上传选项
  2. 对于远程:输入要下载的文件所在的目录名称
  3. 对于远程:输入要下载的文件名
  4. 对于本地:浏览到要将文件下载到的所需目录
  5. 对于本地:输入文件名以将下载的文件另存为(除非要更改,否则使用与要下载的文件相同的文件名)
  6. 选中“立即开始传输”并单击“确定”
  7. 下载应立即开始
  8. 注意:如果您忘记勾选“立即开始传输”... 没问题:只需右键单击要下载的文件(在 FileZilla 窗口窗格底部的进程队列(文件传输队列)中,然后选择“进程队列”
  9. 下载过程应立即开始
  10. 完毕