Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
I have one simple code as below:

XML
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <string>
#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <windows.h>
#include <wininet.h>
#include <winnt.h>

using namespace std;

int main() {
       //LPCTSTR server = _T("ftp.fxturn.com/public_html/data");
       LPCTSTR server = _T("www.www.com");
       LPCTSTR path = _T("/public_html/data");


INTERNET_PORT port = INTERNET_DEFAULT_FTP_PORT;
LPCTSTR user = _T("user");
LPCTSTR pass = _T("pass");
DWORD service = INTERNET_SERVICE_FTP;
DWORD context = 0;
LPCTSTR szLocalFile = _T("C:\\files\\a.csv");

LPCTSTR szRemoteFile = _T("reza444");


    HINTERNET hSession = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
    HINTERNET hService = InternetConnect(hSession, server, INTERNET_DEFAULT_FTP_PORT, user, pass, INTERNET_SERVICE_FTP, 0, 0);
       FtpSetCurrentDirectory(hService, path);

       if(!FtpPutFile(hService, szLocalFile, szRemoteFile, FTP_TRANSFER_TYPE_BINARY, 0)) cout<<"False";
    InternetCloseHandle(hService);
    InternetCloseHandle(hSession);
       
       MessageBox(NULL,szLocalFile,0,0);
       getch();
    return 0;
}


My code in this type works correctly and ftp my file very good.
But When I try use this code in another my projects that is one dll not works correctly and only create file and not ftp content of file.
In my dll I used that as one void function.

XML
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <string>
#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <windows.h>
#include <wininet.h>
#include <winnt.h>

using namespace std;

void ftp() {
       //LPCTSTR server = _T("ftp.fxturn.com/public_html/data");
       LPCTSTR server = _T("www.www.com");
       LPCTSTR path = _T("/public_html/data");


INTERNET_PORT port = INTERNET_DEFAULT_FTP_PORT;
LPCTSTR user = _T("user");
LPCTSTR pass = _T("pass");
DWORD service = INTERNET_SERVICE_FTP;
DWORD context = 0;
LPCTSTR szLocalFile = _T("C:\\Program Files (x86)\\MetaTrader - Alpari UK\\experts\\files\\a.csv");

LPCTSTR szRemoteFile = _T("reza444");


    HINTERNET hSession = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
    HINTERNET hService = InternetConnect(hSession, server, INTERNET_DEFAULT_FTP_PORT, user, pass, INTERNET_SERVICE_FTP, 0, 0);
       FtpSetCurrentDirectory(hService, path);

       if(!FtpPutFile(hService, szLocalFile, szRemoteFile, FTP_TRANSFER_TYPE_BINARY, 0)) cout<<"False";
    InternetCloseHandle(hService);
    InternetCloseHandle(hSession);
       
}


Please help for find problem.
Regards,
Posted
Comments
Sergey Alexandrovich Kryukov 8-Sep-11 16:50pm    
Script?! Ever head C++ is compiling language? :-)
--SA

Does your FtpPutFile function fail? If so, check the error returned by calling GetLastError(). That will help you to find the exact problem.
 
Share this answer
 
Comments
Simon Bang Terkildsen 9-Sep-11 13:24pm    
OP wrote
Hi,
I got this error:
http://fxturn.com/error/error.jpg[^]

Regards,
Hi,
For dll I got error 12002.
VB
ERROR_WINHTTP_TIMEOUT

    12002


How to solve that?
regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900