|
inlib
1.2.0
|
Classes | |
| class | cache |
Functions | |
| bool | wget_file (std::ostream &a_out, const std::string &a_url, const std::string &a_local, bool a_verbose=false) |
| bool | ftp_file (std::ostream &a_out, const std::string &a_url, const std::string &a_local, bool a_verbose=false) |
| bool | http_file (std::ostream &a_out, const std::string &a_url, const std::string &a_local, bool a_verbose=false) |
| bool inlib::web::ftp_file | ( | std::ostream & | a_out, |
| const std::string & | a_url, | ||
| const std::string & | a_local, | ||
| bool | a_verbose = false |
||
| ) | [inline] |
Definition at line 85 of file web.
{
::remove(a_local.c_str());
std::string host;
std::string path;
if(!inlib::net::ftp::parse(a_url,host,path)) return false;
if(a_verbose) {
a_out << "inlib::ftp_file :"
<< " host " << inlib::sout(host)
<< " path " << inlib::sout(path)
<< std::endl;
}
inlib::net::ftp ftp(a_out,a_verbose);
if(!ftp.start(host,inlib::net::ftp::s_anonymous(),"")) return false;
if(!ftp.fetch_file(path,a_local)) return false;
if(a_verbose) {
a_out << "inlib::ftp_file :"
<< " fetch " << sout(a_url) << " end."
<< std::endl;
}
return true;
}
| bool inlib::web::http_file | ( | std::ostream & | a_out, |
| const std::string & | a_url, | ||
| const std::string & | a_local, | ||
| bool | a_verbose = false |
||
| ) | [inline] |
Definition at line 114 of file web.
{
::remove(a_local.c_str());
std::string host;
std::string path;
if(!inlib::net::http::parse(a_url,host,path)) return false;
if(a_verbose) {
a_out << "inlib::http_file :"
<< " host " << inlib::sout(host)
<< " path " << inlib::sout(path)
<< std::endl;
}
inlib::net::http http(a_out,a_verbose);
if(!http.start(host)) return false;
if(!http.fetch(path,a_local)) return false;
if(a_verbose) {
a_out << "inlib::http_file :"
<< " fetch " << sout(a_url) << " end."
<< std::endl;
}
return true;
}
| bool inlib::web::wget_file | ( | std::ostream & | a_out, |
| const std::string & | a_url, | ||
| const std::string & | a_local, | ||
| bool | a_verbose = false |
||
| ) | [inline] |
Definition at line 14 of file web.
{
std::string cmd;
if(inlib::getenv("INLIB_WGET",cmd)) {
} else {
#ifdef WIN32
cmd = "C:\\cygwin\\bin\\curl.exe --silent --compressed --output";
#else
#ifdef __APPLE__
cmd = "curl --silent --compressed --output";
#else // Linux
cmd = "wget -O";
#endif
#endif
}
std::string local;
if(a_local.size()) {
local = a_local;
} else {
local = base_name(a_url);
}
cmd += " ";
cmd += local;
cmd += " ";
cmd += a_url;
::remove(local.c_str());
if(a_verbose) {
a_out << "inlib::wget_file :"
<< " call ::system(" << sout(cmd) << ") ..."
<< std::endl;
}
if(::system(cmd.c_str())==(-1)){
a_out << "inlib::wget_file :"
<< " call to ::system(" << sout(cmd) << ") failed."
<< std::endl;
return false;
}
//WARNING : the call to system(cmd) may be ok, but the command
// may have failed !
if(!inlib::file::exists(local)) {
a_out << "inlib::wget_file :"
<< " can't get " << sout(a_url) << "."
<< std::endl;
return false;
}
std::vector<std::string> txt;
if(!inlib::file::read_num(local,3,txt)) {
a_out << "inlib::wget_file :"
<< " can't read head of " << sout(local) << "."
<< std::endl;
::remove(local.c_str());
return false;
}
if((txt.size()>=3)&&(txt[2]=="<title>404 Not Found</title>")) {
a_out << "inlib::wget_file :"
<< " url " << sout(a_url) << " not found."
<< std::endl;
::remove(local.c_str());
return false;
}
//::printf("debug : curl_file : \"%s\" end\n",a_url.c_str());
return true;
}
1.7.5.1