예제 #1
0
파일: ftpget.c 프로젝트: exuuwen/study
int main(int argc, char* argv[])
{
	if(argc != 3)
	{
		printf("usage: ./main  ftp_uri  savefile\n");
		return -1;
	}


	int ret = CurlDownload(argv[1], argv[2]);
	if(ret != 0)
	{
		printf("download error %d\n", ret);
		return -1;
	}

	printf("%s: success to download %s to %s\n", __FUNCTION__, argv[1], argv[2]);

	return 0;

}
예제 #2
0
uint32 FileDownloader::DownloadFile()
{
    Logger::Instance()->Debug("Start download");

    fileForWrite = NULL;
    
    std::string path = "";
    std::string fileName = "";
    FileSystem::Instance()->SplitPath( GetSourceUrl(), path, fileName );
    std::string fullSavePath = FileSystem::Instance()->RealPath( FileSystem::Instance()->SystemPathForFrameworkPath( GetSavePath() ) + "/" + fileName );
    
    // Check file exist
    fileForWrite = FileSystem::Instance()->CreateFileForFrameworkPath(fullSavePath, File::OPEN | File::READ);
    
    if (fileForWrite == NULL)
    {
        // If fole not exist create new file
        fileForWrite = FileSystem::Instance()->CreateFileForFrameworkPath(fullSavePath, File::CREATE | File::WRITE);
    }
    else if (reloadFile == false)
    {
        // Open file for APPEND and get pos to resume download
        SafeRelease(fileForWrite);
        fileForWrite = FileSystem::Instance()->CreateFileForFrameworkPath(fullSavePath, File::APPEND | File::WRITE);
    }
    else
    {
        // Reload exist file from server
        SafeRelease(fileForWrite);
        fileForWrite = FileSystem::Instance()->CreateFileForFrameworkPath(fullSavePath, File::CREATE | File::WRITE);
    }
    
    // Error read, write or create file
    if ( fileForWrite == NULL && delegate != NULL)
    {
        delegate->DownloadComplete(FileDownloaderDelegate::DL_ERROR_FILE_SYSTEM);
        return CURL_LAST;
    }
    
    uint32 status;
    do
    {
        if (reconnectCnt > 0 && delegate != NULL)
        {
            delegate->DownloadReconnect();
        }
        status = CurlDownload();
        ++reconnectCnt;
    }
    while ( status != CURLE_OK && ( reconnectCnt < reconnectMax || reconnectMax == -1 ) );
    SafeRelease(fileForWrite);
    
    //
    if ( status == CURLE_OK && delegate != NULL )
    {
        delegate->DownloadComplete(FileDownloaderDelegate::DL_SUCCESS);
    }
    else if ( delegate != NULL )
    {
        delegate->DownloadComplete(FileDownloaderDelegate::DL_ERROR_DOWNLOAD);
    }

    Logger::Instance()->Debug("End download");
    
    return status;
}