Downloading File with libcurl in c++ - c++

I am trying to download a zip file from a website but running into a few issues.
http://ampaste.net/m1632f19a
I implemented libcurl, followed some examples on downloading a file, used a big zip file so I could watch the progress %. It takes about 20 seconds to download, when it completes I go look and there is no file.
Anyone have any ideas?

Here is a related question
This post seems to use
double* Bar;
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar);
maybe it is a progress specific problem. Have you tried without the progress stuff?

Related

How to write log file so that it can be read with notepad in real time for C++

I need a logger for C++. And I found this post Small logger class, which led me to this simple logger http://www.drdobbs.com/cpp/201804215.
It mainly uses the following method to wirte to log file.
FILE* pFile = fopen("application.log", "a");
std::ostringstream os;
os<<"I am a log line."<<std::endl;
fprintf(pFile, "%s", os.str().c_str());
fflush(pFile);
But it doesn't work as I expected. I assume, with the log file open in notepad, each new log line would be showing immediately after fprintf and fflush. But it turned out that I have to close and reopen the file with notepad to see the update.
So is there a way to write log file in C++ that allows reading in real time, which makes the log file resemble win32 console or VS output window? I miss the days when I can dump everything to console.log in Javascript. :)
Thanks.
This is not a problem with your code, this is an issue with Notepad.
Notepad does not automatically check for changes in the file you have open.
Instead, you should use a tool that does, for instance Notepad++, or indeed most editors designed for programmers.
If you have installed cygwin, you could also use tail -f to monitor additions to the log file.
After the accepted answer from mjs pointed me in the right direction, I google searched "notepad auto refresh" and found this https://www.raymond.cc/blog/monitor-log-or-text-file-changes-in-real-time-with-notepad/.
It provides several options to monitor text file changes in Windows, including Notepad++ and other software specifically designed for monitoring text file changes, with features like keyword filter/highlight and save/load monitoring session.
You might find It interesting if you came across the same problem as mine. Cheers.

How can I get the progress of an FTP Download in WinInet C++

I'm creating a program which downloads a file from an FTP server. I want to display the progress of how much bytes the user has downloaded. I have tried searching for it but I couldn't find anything. First , my plan was to get the file size using fstream but then I realized that I can't share 2 processes at the same time.
I assume you're using FtpGetFile(..) to download the file from the FTP server. This is the simple way of downloading a file which gives you no information about how many bytes are already downloaded and you have very little control how the function behaves (e.g. cancelling of a download upon user request?). For quick test it is very helpful, though.
In order to monitor the download progress do the following:
Determine size of remote file using FtpFindFirstFile.
Open remote file using FtpOpenFile.
Create local file using CreateFile.
Read some bytes from remote file using InternetReadFile.
Evaluate return value and error code of InternetReadFile the detect errors and if transmittion is complete.
Write these bytes to local file using WriteFile.
Calculate/Update your progress information.
Go back to step 4 if file is not downloaded entirely and there is no error.
Close local file using CloseHandle.
Close remote file using InternetCloseHandle.
If you need more help I can offer some code doing this...

How to handle downloading file progress by DropNet

I'm using DropNet to download file from Dropbox, I see it use the RestClient for execute the reques.
My question:
Is there anyway to get progress status during the Download?
I mean, if I'm downloading a few Megabyte file size, how I'll know that the download is in progress?!
Shouldn't we have for example callback for inform the caller about status?, each package call this call bace with status like package number?, so client can wait or retry...?
Thanks
Joseph
Sadly the answer to this is no. RestSharp doesn't support this so DropNet doesn't either.
You could proabably take a look at DropNetRT which is based off HttpClient https://github.com/dkarzon/DropNetRT. It doesn't currently support progress out of the box but could be modified using something similar to this: https://stackoverflow.com/a/8492195/75946
If you do have a go at this let me know so I can either help you out or include your changes into the project. I've had a bit of feedback for this feature but haven't found a good way to do it yet.

file moved when system writing information in file C ++

I am not sure if this is even a valid question. I am not a master at understanding the workings of system. One of my program writes logs to a text file. Another email program runs on scheduler and emails and archives the log file if found in the folder.
My question is, If at any given instant if the first program is writing information into the file and at the same time email scheduler runs what will happen? Will the email program be able to mail the file and archive it? If Yes, will the earlier program writing the file crash? How to handle this scenario without crashing either programs?
No matter what, your setup will lead to some kind of trouble.
I think the simplest solution would be to have the program that writes the log file do this e.g. 5 minutes before the emailer/archiver is scheduled to run:
start a new file for logging
copy or rename the old file to the file that the emailer/archiver uses.

FTP folders synchronization c / obj c

I have folder (with a lot of sublfolders and files) on remote server and only FTP protocol supported.
I should have synchronized copy on my device every time when user press "SYNC" button.
Content has size more than 1gb - download every time is not good idea :)
I've trying get folders structure (recursively via LIST and CWD) and get files modification date to analyze - should I download this file or no.
Is it one correct way or I missed better solution ? For now it can take around 4 minutes only for get files structure :(
Is it possible get all folders structure with filecustom fields (like modification date)?
Im on objC (iOS) and using CFNetwork sample from SimpleFTPSample (from Apple).
update:
I've found dir -R command - is this command standard (like LIST) or no ?
thanks,
I've replace library to libCURL and now it works in 1 sec... I'm shock!