The Windows ftp client ftp.exe does not support passive mode. It does not contain a passive command. You can issue the passive command (PASV) through the use of the 'literal' or 'quote' command but this will only put the server in passive mode. However the Windows client will still be using active mode.
This was known as passive mode, or PASV, after the command used by the client to tell the server it is in passive mode. In passive mode FTP the client initiates both connections to the server, solving the problem of firewalls filtering the incoming data port connection to the client from the server.
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.
Using the quote pasv
won't help. It switches only the server to the passive mode, but not the client.
Use any thirdparty Windows FTP command-line client instead. Most other support the passive mode.
For example WinSCP defaults to the passive mode and there's a guide available for converting Windows FTP script to WinSCP script. If you are starting from the scratch, see the guide to automating file transfers to FTP using WinSCP. Also, WinSCP GUI can generate a script template for you.
(I'm the author of WinSCP)
Windows does not actually support passive mode.
You can send the command to the server in three different ways but that will not enable passive mode on the Windows client end.
Those arguments are for sending various commands and pasv
is not something that Microsoft thought of when they wrote it.
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.
Although this doesnt answer the question directly about command line, but from Windows OS, use the Windows Explorer ftp://username@server
this will use Passive Mode by default
For command line, active mode is the default
The quote PASV
command is not a command to the ftp.exe
program, 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.
The windows ftp.exe
program 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.exe
is necessary as FTPing to localhost as one of the connections won't work in most windows environments.
You can effect a passive FTP transfer between two different hosts (but not two connections on the same host) as follows:
Open up two prompts, use one to ftp.exe
connect to your source FTP server and one to ftp.exe
connect to your destination FTP server.
Now establish a passive connection between the servers using the raw commands PASV and PORT. The quote PASV
command 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)
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.
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
CURL client supports FTP protocol and works for passive mode. Get Download WITHOUT SSL version 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
http://www.paehl.com/?CURL_7.79.1
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
echo n | psftp.exe ftp.server.com -l myuser -pw mypwd -b script.txt
script.txt (any ftp command may be typed)
put "C:\test\myfile.dat" "/some/folder/myfile.dat"
quit
If you are using Windows 10, install Windows Subsystem for Linux, WSL and Ubuntu.
$ 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With