Download MetaTrader 5
To add comments, please log in or register
Have you found an error in our products? Apply to Service Desk!
NewWin
245
NewWin 2014.04.11 19:48 

Hi everybody,

I want to send file from MT4 to my server but I want to put all parameter (FTP server, FTP path, FTP login, password) in the EA/Script, not in FTP setting tab of MT4.

Does anyone know how to do this with SendFTP function? Or even if SendFTP cannot help, is there any imported DLL function can do this?

Thank you in advance.

Alain Verleyen
Moderator
28606
Alain Verleyen 2014.04.11 20:47  
Kienvu:

Hi everybody,

I want to send file from MT4 to my server but I want to put all parameter (FTP server, FTP path, FTP login, password) in the EA/Script, not in FTP setting tab of MT4.

Does anyone know how to do this with SendFTP function? Or even if SendFTP cannot help, is there any imported DLL function can do this?

Thank you in advance.

SendFTP is built-in function from mql4, you can only use it with FTP setting tab.

You can use ShellExecuteW from WinApi and ftp command from Windows.

NewWin
245
NewWin 2014.04.12 06:29  
angevoyageur:

SendFTP is built-in function from mql4, you can only use it with FTP setting tab.

You can use ShellExecuteW from WinApi and ftp command from Windows.



Thank you, angevoyageur, but I don't know how the ShellExecuteW work with FTP, can you show me?

However, I've found this code on forum and tried to test with my server but it failed.

My FTP server information is: Username: "user", Password: "password", Server: "www.tool4fx.com", FTP path: "/httpdocs/FTP_test".

I can access it by type this to the Browser: ftp://user:password@ftp.tool4fx.com/ . But still don't know how to put it in the code.

Can anyone please help me to solve this? Thanks

//+------------------------------------------------------------------+
//|                                           UploadingFileTest.mq4  |
//|                                                         mestize  |
//|                               "http://www.forexmq4.blogspot.com" |                                                                 |
//+------------------------------------------------------------------+
#property copyright "Mestize"
#property link      "http://www.forexmq4.blogspot.com"

//IF THIS FILE IS SUITABLE FOR YOU, PLEASE, DON'T FORGET TO CLICK FROM TIME TO TIME
//IN www.forexmq4.blogspot.com, THANK YOU SO MUCH.


//Definition of constants employed later. These definitions were obtained from the wininet.h file of my operating system
#define INTERNET_SERVICE_FTP    1
#define INTERNET_SERVICE_GOPHER 2
#define INTERNET_SERVICE_HTTP   3

#define FTP_TRANSFER_TYPE_UNKNOWN   0x00000000
#define FTP_TRANSFER_TYPE_ASCII     0x00000001
#define FTP_TRANSFER_TYPE_BINARY    0x00000002


//Importing the proper API functions to Upload a file from the proper windows library wininet.dll
//Please see Microsoft reference wininet API functions at http://msdn.microsoft.com/en-us/library/aa385473(VS.85).aspx
#import "wininet.dll"
   //To open an "empty" Internet Object
   int InternetOpenW(string Agent, int AccessType, string ProxyName, string ProxyBypass, int Flags);
   //To create a working session (connection) with the Internet Object previously created
   int InternetConnectW(int hInternetSession, string ServerName, int ServerPort, string UserName, string Password, int Service, int Flags, int Context);
   //To, in this case, uploading a file
   bool FtpPutFileW(int hFtpSession, string LocalFile, string RemoteFile, int Flags, int Context);
   //To close the Internet Object and its connections
   bool InternetCloseHandle(int hInet);
#import


//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----

   int hIntObj, hIntObjConn;
   string Password, ServerName, UserName, LocalFile, HostFile;
   bool Success;
  
   //Uploading the file
   hIntObj=InternetOpenW("MyInternetObjectName",1,NULL,NULL,NULL);//We create an object of type "Internet"
   if (hIntObj>0)
      {
         ServerName="www.tool4fx.com";//Your ftp server
         UserName="user";//Your username you use when manually establish a ftp session
         Password="password";//Your password you use when manually establish a ftp session
         hIntObjConn=InternetConnectW(hIntObj, ServerName, 0, UserName, Password, INTERNET_SERVICE_FTP, NULL, NULL);//We hang a FTP session on our internet object created.
         //The session could have been a HTTP session or even a HTTPS session.
         //See http://msdn.microsoft.com/en-us/library/aa385473(VS.85).aspx
         if (hIntObjConn>0)
            {
               LocalFile="Hi.txt";//The physical address in your local machine where the file to be uploaded is. (I put this file in MQL4/Files folder)
               HostFile="Hi.txt";//The name of the remote file uploaded
               Success=FtpPutFileW(hIntObjConn, LocalFile, HostFile, FTP_TRANSFER_TYPE_BINARY, NULL);
            }
      }
   InternetCloseHandle(hIntObj);
   
   if (Success==FALSE) MessageBox("Uploading error. Check the name and root of your file to be uploaded and your username and password of your ftp server","http://www.forexmq4.blogspot.com",1);
   else MessageBox("Uploading sucessfull!!","http://www.forexmq4.blogspot.com",1);

     
//----
   return(0);
  }
//+------------------------------------------------------------------+
/
To add comments, please log in or register