| | |
Get size of a remote file
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Too bad you're not using PHP.
http://ca2.php.net/filesize
But it seems like it might not be possible: http://bytes.com/groups/php/595984-f...ing-http-pages
On the other hand, wget determines file sizes. Apparently it requires HTTP 1.1 (not 1.0) to do this.
I really don't know. You'd have to do some research.
http://ca2.php.net/filesizeBut it seems like it might not be possible: http://bytes.com/groups/php/595984-f...ing-http-pages
On the other hand, wget determines file sizes. Apparently it requires HTTP 1.1 (not 1.0) to do this.
I really don't know. You'd have to do some research.
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
•
•
Join Date: Jun 2009
Posts: 9
Reputation:
Solved Threads: 0
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdio> #include <curl/curl.h> #include <boost/regex.hpp> using namespace boost; using namespace std; // // For this demonstration, the contents of the web page are put // into this global variable. // string contents; // // This is the callback function that is called by // curl_easy_perform(curl) // size_t handle_data(void *ptr, size_t size, size_t nmemb, void *stream) { const boost::regex content_length_regex("Content-Length: [0-9]{1,}"); // Regex do video do youtube... const boost::regex content_length_remove_regex("Content-Length: "); int numbytes = size*nmemb; // The data is not null-terminated, so get the last character, and replace // it with '\0'. char lastchar = *((char *) ptr + numbytes - 1); //string last_char = char_to_string(lastchar); // { string nothing = ""; // contents = regex_replace(last_char, content_length_remove_regex, nothing); *((char *) ptr + numbytes - 1) = '\0'; string last_char = ((char *)ptr); //cout << last_char << endl; //cout << endl; //cout << regex_search(last_char,content_length_regex) << endl; //cout << endl; //cout << "antes" << endl; //cout << ((char*)ptr) << endl; if (regex_search(last_char,content_length_regex) == 1) // Se for 1, foi retornado sim para o match { //cout << "depois" << endl; //cout << ((char*)ptr) << endl; //cout << regex_replace(last_char, content_length_remove_regex, nothing) << endl; contents = regex_replace(last_char, content_length_remove_regex, nothing); //cout << contents << endl; } else //{ //contents = "-1"; //} //contents.append((char *)ptr); //contents.append(1,lastchar); //*((char *) ptr + numbytes - 1) = lastchar; // Might not be necessary. // } return size*nmemb; } long remote_filesize(string url) { //string url = "http://www.youtube.com/get_video?video_id=3455GI_uGs4&t=vjVQa1PpcFNWk-V5Ndo6HE9KWZGtRxrct9PNWGe5Nhs=&el=detailpage&ps=&fmt=34"; //string url = "http://www.google.com"; CURL *curl; CURLcode res; double length = 0.0; //double length2 = 0.0; curl = curl_easy_init(); if(curl) { //static const char *headerfilename = "head.out"; //FILE *headerfile; //headerfile = fopen(headerfilename,"w"); curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); //curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL); //curl_easy_setopt(curl, CURLOPT_RANGE, "0-4"); // só por garantia, não faz o donwload inteiro não... curl_easy_setopt(curl, CURLOPT_NOBODY, 1); // acho que é aqui que bloqueia o donwload... curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, handle_data); curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 500); res = curl_easy_perform(curl); //curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &length); //cout << length << endl; //const boost::regex youtube_video_id("^video_id="); // Regex do video do youtube... //cout << contents << endl; //unlink(headerfilename); } curl_easy_cleanup(curl); //return length; if (contents == "") { return(-1); } else { return atol(contents.c_str()); } } int main() { // Content-Length: 222 string url = "http://www.google.com.br"; remote_filesize(url); cout << "contents " << contents << endl; return 0; }
Sorry for the comments in Portuguese and snippets of code. I had to use the libboost_regex because I still do not know another way to do a search for regular expression.
Last edited by osmano807; Jun 9th, 2009 at 2:32 pm.
http://www.thundercache.org
ThunderCache, a proxy that cache's youtube and more!
ThunderCache, a proxy that cache's youtube and more!
![]() |
Similar Threads
- Get last modified timestamp of remote file (C++)
- find the size of log file using vb.net¿¿¿¿ (VB.NET)
- problem reading remote file (Perl)
- file size (C++)
- File size in C (Win32) (C)
- is it possible to change the size of jpg file through programming in vb (Visual Basic 4 / 5 / 6)
- Obtain Remote Assistance by Sending an E-mail Message in Windows XP (Windows tips 'n' tweaks)
- Obtain Remote Assistance by Sending an E-mail Message in Windows XP (Windows tips 'n' tweaks)
- Cannot Use MSN EXPLORER or AOL To Send a Remote Assistance Invitation (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: BSOD C::B + sdl + vista
- Next Thread: Need help with this macro...
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





