Raised This Month: $12 Target: $400
 3% 

[cURL] File isn't downloaded completely


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
floube
SourceMod Donor
Join Date: Jan 2013
Location: Austria
Old 05-09-2014 , 03:32   [cURL] File isn't downloaded completely
Reply With Quote #1

Hey there

just messing around with cURL and FTP.

It does create the file and it also downloads, but not completely so 359 KB would be 356 KB but after some time it randomly seems to finish the download. Look at the image (https://i.imgur.com/bkJR6H2.jpg), it is missing some pixels at the bottom.

It's weird, someone knows more?

PHP Code:
public cURL_DownloadFileFTP(String:sUrl[], String:sDestinationFile[], String:sUser[], String:sPassword[]) {
    new 
Handle:hFile INVALID_HANDLE;
    new 
Handle:hCurl curl_easy_init();

    new 
String:sLogin[256];
    
Format(sLoginsizeof(sLogin), "%s:%s"sUsersPassword);

    if (
hCurl != INVALID_HANDLE) {
        
curl_easy_setopt_int_array(hCurlCURL_Default_optsizeof(CURL_Default_opt));
        
hFile cURL_CreateFile(sDestinationFile"w");

        
curl_easy_setopt_handle(hCurlCURLOPT_WRITEDATAhFile);

        
curl_easy_setopt_int(hCurlCURLOPT_SSL_VERIFYPEER0);
        
curl_easy_setopt_int(hCurlCURLOPT_SSL_VERIFYHOST2);
        
curl_easy_setopt_string(hCurlCURLOPT_USERPWDsLogin);

        
curl_easy_setopt_string(hCurlCURLOPT_URLsUrl);

        
curl_easy_perform_thread(hCurlcURL_OnComplete);
    } else {
        
PrintToServer("FTP Failed: Could not create cURL handle.");
    }
}

public 
Handle:cURL_CreateFile(const String:sPath[], const String:sMode[]) {
    new 
String:sPathTemp[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMsPathTempsizeof(sPathTemp), sPath);

    return 
curl_OpenFile(sPathTempsMode);
}

public 
cURL_OnComplete(Handle:hCurlCURLcode:iCodeany:iData) {
    if (
hCurl != INVALID_HANDLE && iCode != CURLE_OK) {
        new 
String:sError[256];
        
curl_easy_strerror(iCodesErrorsizeof(sError));

        
PrintToServer("FTP Failed: "sError);
        return;
    }

    
PrintToServer("FTP succeeded");
    
    
CloseHandle(hCurl);
    
hCurl INVALID_HANDLE;

__________________
floube is offline
floube
SourceMod Donor
Join Date: Jan 2013
Location: Austria
Old 05-18-2014 , 16:15   Re: [cURL] File isn't downloaded completely
Reply With Quote #2

bump. Anyone?
__________________
floube is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 05-19-2014 , 09:01   Re: [cURL] File isn't downloaded completely
Reply With Quote #3

If it's a windows machine, try open file in binary mode. "wb" instead of "w" in hFile = cURL_CreateFile(sDestinationFile, "w");
xf117 is offline
Send a message via ICQ to xf117
floube
SourceMod Donor
Join Date: Jan 2013
Location: Austria
Old 05-20-2014 , 08:47   Re: [cURL] File isn't downloaded completely
Reply With Quote #4

Using this on a linux machine, maybe someone already did FTP downloading and can post his code here?
__________________
floube is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode