Connect to FTP server.

Samuel Manoel De Souza  
class FTP
  {
   string            m_url, m_user, m_pass;
   int               m_inet;
   int               m_session;
public:
                     FTP(string url, string user, string pass)
      :              m_url(url), m_user(user), m_pass(pass) {}
                    ~FTP(void) {}
   bool              Connect(void)
     {
      ResetLastError();
      m_inet = InternetAttemptConnect(0);
      if(m_inet != ERROR_SUCCESS)
        {
         Print("Internet connection failed.");
         return false;
        }
      m_session = InternetConnectW(m_inet, m_url, 21, m_user, m_pass, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
      if(m_session == NULL)
        {
         Print("FTP connection failed.");
         InternetCloseHandle(m_inet);
         return false;
        }
      return true;
     }
  };

I'm trying to connect to an FTP server but it always fails. Above is what i'm doing. Has anyone already made that?

Alain Verleyen  
You need to downloaded files from this server ?
Samuel Manoel De Souza  
Alain Verleyen #:
You need to downloaded files from this server ?

yes. i have the url, user and password.

Alain Verleyen  
Samuel Manoel De Souza #:

yes. i have the url, user and password.

You need to use InternetOpenW() to get your "m_inet" handle, not InternetAttemptConnect().

See this article...

Using WinInet.dll for Data Exchange between Terminals via the Internet
Using WinInet.dll for Data Exchange between Terminals via the Internet
  • www.mql5.com
This article describes the principles of working with the Internet via the use of HTTP requests, and data exchange between terminals, using an intermediate server. An MqlNet library class is presented for working with Internet resources in the MQL5 environment. Monitoring prices from different brokers, exchanging messages with other traders without exiting the terminal, searching for information on the Internet – these are just some examples, reviewed in this article.
Samuel Manoel De Souza  
Alain Verleyen #:

You need to use InternetOpenW() to get your "m_inet" handle, not InternetAttemptConnect().

See this article...

I tried that yesterday and did not work. I probably made something wrong. It connects now.

Reason: