Connect to FTP server.

 
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?

 
You need to downloaded files from this server ?
 
Alain Verleyen #:
You need to downloaded files from this server ?

yes. i have the url, user and password.

 
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.
 

See also...

Metatrader5 MacOS - Problem with Wininet.dll and FtpGetFileW
Metatrader5 MacOS - Problem with Wininet.dll and FtpGetFileW
  • 2023.02.13
  • www.mql5.com
Hello everyone, I recently coded an expert that allows me to automatically download various files from my FTP server and also upload my trading sta...
 
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.