0

I use WinInet to connect to an FTP server. I use FtpCommand() to send a "PASV" command to switch from Active to Passive mode. I am now searching for the opposite command to switch from Passive to Active mode. Does anyone know how to do this?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Vas
  • 75
  • 9
  • Why is this question tagged as C++? – Dai Jun 07 '17 at 14:00
  • why the minus on the question ? i use c++ for the ftp connections. If i didnt i am sure you would be the same one to ask in which program language you are asking for ... And if you dont know the answer better not ruine others questions ... – Vas Jun 07 '17 at 14:10
  • If you tag question with C++, we expect some C++ code. It's completely unclear, what you question is about. Are you implementing FTP client in C++ from scratch? – Martin Prikryl Jun 07 '17 at 14:21
  • I use wininet, and as the question says very clear i use the command "PASV" to switch from active to passive mode, i am searching the oposite command or way to switch from passive to active while connected to an ftp server... – Vas Jun 07 '17 at 14:24
  • Where does your question say "wininet"? It does not make any sense without that information! How do you use "PASV" with wininet? It does not make sense either. Show us your code! – Martin Prikryl Jun 07 '17 at 14:35

1 Answers1

2

Active mode is enabled by sending a PORT (or EPRT) command instead of sending a PASV (or EPSV) command. PORT/EPRT tells the server which IP/port it needs to actively connect to on your system.

If you want to understand how the FTP protocol works, I suggest you read the FTP specification, RFC 959, and its various extensions, particularly RFC 2428 and RFC 3659.

In WinInet, the transfer mode is typically established at the beginning of the session when you call InternetConnect() or InternetOpenUrl(). If you specify the INTERNET_FLAG_PASSIVE flag, it forces Passive mode. If you do not specify the flag, the mode is determined by the user's default Internet Options. This mode allows the FtpGetFile()/FtpPutFile() and FtpFindFirstFile()/InternetFindNextFile() functions to operate over their own data connections. Once the mode is established for a session, it cannot be changed, AFAIK.

However, you can use FtpCommand() to send any FTP command manually, including PASV/EPSV and PORT/EPRT. If you set the fExpectResponse parameter to TRUE, the phFtpCommand output parameter will give you a new HINTERNET handle if a data socket is created. You can use that handle with InternetReadFile() and InternetWriteFile() to transfer files and directory listings over that data connection.

Community
  • 1
  • 1
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thank Remy, indeed i use wininet and internetconnect() without specifying a flag but as tested in local it can change to enter passive mode with the ftpcommand and "PASV" option. (i never tested it to online servers yet) I will try the same with the EPRT command maby with a bit of luck it does the trick at least at local ftp server. (i will later check these two options on the online servers and see what going on).Maby reconnect with the new option should do the trick if it cant be changed while connected – Vas Jun 07 '17 at 16:36