28 #if defined (HAVE_CONFIG_H) 43 #if defined (HAVE_CURL) 44 # include <curl/curl.h> 45 # include <curl/curlver.h> 46 # include <curl/easy.h> 72 errmsg =
"__ftp_mget__: can not create directory '" 102 std::ofstream
ofile (realfile.c_str (),
103 std::ios::out | std::ios::binary);
105 if (!
ofile.is_open ())
108 errmsg =
"__ftp_mget__: unable to open file";
172 errmsg =
"__ftp__mput: file '" + realfile
173 +
"' does not exist";
187 std::ifstream ifile (realfile.c_str (), std::ios::in |
190 if (! ifile.is_open ())
193 errmsg =
"__ftp_mput__: unable to open file '" 205 file_list.
append (realfile);
212 errmsg =
"__ftp_mput__: can not read the directory '" 220 #if defined (HAVE_CURL) 223 write_data (
void *buffer,
size_t size,
size_t nmemb,
void *streamp)
225 std::ostream&
stream = *(
static_cast<std::ostream *
> (streamp));
226 stream.
write (static_cast<const char *> (buffer), size*nmemb);
227 return (
stream.fail () ? 0 : size * nmemb);
231 read_data (
void *buffer,
size_t size,
size_t nmemb,
void *streamp)
233 std::istream&
stream = *(
static_cast<std::istream *
> (streamp));
234 stream.
read (static_cast<char *> (buffer), size*nmemb);
238 return (
stream.fail () ? 0 : size * nmemb);
244 return static_cast<size_t>(size * nmemb);
250 #define SETOPT(option, parameter) \ 253 CURLcode res = curl_easy_setopt (curl, option, parameter); \ 254 if (res != CURLE_OK) \ 257 errmsg = curl_easy_strerror (res); \ 264 #define SETOPTR(option, parameter) \ 267 CURLcode res = curl_easy_setopt (curl, option, parameter); \ 268 if (res != CURLE_OK) \ 271 errmsg = curl_easy_strerror (res); \ 288 errmsg =
"can not create curl object";
300 errmsg =
"can not create curl object";
304 init (user_arg, passwd, std::cin,
os);
306 url =
"ftp://" + host;
321 errmsg =
"can not create curl object";
325 init (
"",
"", std::cin,
os);
328 if (! cainfo.empty ())
329 SETOPT (CURLOPT_CAINFO, cainfo.c_str ());
332 if (! capath.empty ())
333 SETOPT (CURLOPT_CAPATH, capath.c_str ());
335 SETOPT (CURLOPT_NOBODY, 0);
341 SETOPT (CURLOPT_HTTPGET, 1);
353 curl_easy_cleanup (
curl);
395 SETOPT (CURLOPT_TRANSFERTEXT, 1);
401 SETOPT (CURLOPT_TRANSFERTEXT, 0);
426 struct curl_slist *slist =
nullptr;
432 slist = curl_slist_append (slist, cmd.c_str ());
433 cmd =
"rnto " + newname;
434 slist = curl_slist_append (slist, cmd.c_str ());
435 SETOPT (CURLOPT_POSTQUOTE, slist);
441 SETOPT (CURLOPT_POSTQUOTE, 0);
448 SETOPT (CURLOPT_UPLOAD, 1);
449 SETOPT (CURLOPT_NOBODY, 0);
457 SETOPT (CURLOPT_NOBODY, 1);
458 SETOPT (CURLOPT_UPLOAD, 0);
467 SETOPT (CURLOPT_NOBODY, 0);
475 SETOPT (CURLOPT_NOBODY, 1);
484 SETOPT (CURLOPT_NOBODY, 0);
490 SETOPT (CURLOPT_NOBODY, 1);
499 std::ostringstream buf;
501 SETOPTR (CURLOPT_WRITEDATA, static_cast<void *> (&buf));
503 SETOPTR (CURLOPT_DIRLISTONLY, 1);
513 SETOPTR (CURLOPT_DIRLISTONLY, 0);
522 pos =
str.find_first_of (
'\n', pos);
523 if (pos == std::string::npos)
532 size_t newpos =
str.find_first_of (
'\n', pos);
533 if (newpos == std::string::npos)
544 time_t& filetime,
bool& fileisdir)
550 SETOPT (CURLOPT_FILETIME, 1);
571 curl_easy_getinfo (
curl, CURLINFO_FILETIME, &ft);
574 curl_easy_getinfo (
curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &
fs);
578 SETOPT (CURLOPT_HEADERFUNCTION, 0);
579 SETOPT (CURLOPT_FILETIME, 0);
594 struct curl_slist *slist =
nullptr;
599 slist = curl_slist_append (slist,
"pwd");
600 SETOPTR (CURLOPT_POSTQUOTE, slist);
603 std::ostringstream buf;
604 SETOPTR (CURLOPT_WRITEHEADER, static_cast<void *>(&buf));
613 size_t pos2 =
retval.rfind (
'"');
614 size_t pos1 =
retval.rfind (
'"', pos2 - 1);
617 SETOPTR (CURLOPT_HEADERFUNCTION, 0);
618 SETOPTR (CURLOPT_WRITEHEADER, 0);
619 SETOPTR (CURLOPT_POSTQUOTE, 0);
630 if (! query_string.empty ())
631 url +=
'?' + query_string;
644 SETOPT (CURLOPT_POSTFIELDS, query_string.c_str ());
651 if (action.empty () || action ==
"get")
653 else if (action ==
"post")
658 errmsg =
"curl_transfer: unknown http action";
687 std::istream&
is, std::ostream&
os)
690 SETOPT (CURLOPT_NOBODY, 1);
694 if (! passwd.empty ())
703 SETOPT (CURLOPT_WRITEDATA, static_cast<void *> (&
os));
709 SETOPT (CURLOPT_READDATA, static_cast<void *> (&
is));
712 SETOPT (CURLOPT_FOLLOWLOCATION,
true);
717 SETOPT (CURLOPT_FTP_USE_EPSV,
false);
719 SETOPT (CURLOPT_NOPROGRESS,
true);
720 SETOPT (CURLOPT_FAILONERROR,
true);
722 SETOPT (CURLOPT_POSTQUOTE, 0);
723 SETOPT (CURLOPT_QUOTE, 0);
728 std::ostringstream query;
736 char *enc_name = curl_easy_escape (
curl,
name.c_str (),
738 char *enc_text = curl_easy_escape (
curl,
text.c_str (),
741 query << enc_name <<
'=' << enc_text;
743 curl_free (enc_name);
744 curl_free (enc_text);
758 struct curl_slist *slist =
nullptr;
766 slist = curl_slist_append (slist, cmd.c_str ());
768 SETOPT (CURLOPT_POSTQUOTE, slist);
775 SETOPT (CURLOPT_POSTQUOTE, 0);
783 #if defined (HAVE_CURL) 784 # define REP_CLASS curl_transfer 786 # define REP_CLASS base_url_transfer octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
void http_get(const Array< std::string > ¶m)
For example cd octave end example noindent changes the current working directory to file
std::string lasterror(void) const
void ftp_file_or_dir_action(const std::string &file_or_dir, const std::string &action)
virtual void put(const std::string &, std::istream &)
int unlink(const std::string &name)
curl_transfer & operator=(const curl_transfer &)=delete
void del(const std::string &file)
std::ostream & set_ostream(std::ostream &os)
void get_fileinfo(const std::string &filename, double &filesize, time_t &filetime, bool &fileisdir)
std::istream & set_istream(std::istream &is)
void add_fcn(void(*fcn)(void))
void put(const std::string &file, std::istream &is)
static size_t throw_away(void *, size_t size, size_t nmemb, void *)
void http_post(const Array< std::string > ¶m)
void http_action(const Array< std::string > ¶m, const std::string &action)
virtual string_vector list(void)
#define SETOPTR(option, parameter)
std::string dir_sep_str(void)
static std::string getenv(const std::string &name)
octave_value resize(const dim_vector &dv, bool fill=false) const
void rmdir(const std::string &path)
nd deftypefn *std::string name
static int write_data(void *buffer, size_t size, size_t nmemb, void *streamp)
curl_transfer(const std::string &url_str, std::ostream &os)
#define SETOPT(option, parameter)
string_vector & append(const std::string &s)
virtual void get_fileinfo(const std::string &, double &, time_t &, bool &)
std::string form_query_string(const Array< std::string > ¶m)
curl_transfer(const std::string &host, const std::string &user_arg, const std::string &passwd, std::ostream &os)
Array< std::string > param
static void reset_path(base_url_transfer *curl_xfer)
void mget_directory(const std::string &directory, const std::string &target)
octave_value read(const Array< double > &size, octave_idx_type block_size, oct_data_conv::data_type input_type, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt, octave_idx_type &count)
octave::unwind_protect frame
virtual void cwd(const std::string &)
int mkdir(const std::string &nm, mode_t md)
std::ofstream ofile(filename.c_str(), std::ios::out|std::ios::binary)
#define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
otherwise an error message is printed The permission mask is a UNIX concept used when creating new objects on a file system such as files
static void delete_file(const std::string &file)
virtual void mkdir(const std::string &)
octave::sys::file_stat fs(filename)
void mkdir(const std::string &path)
#define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
void init(const std::string &user, const std::string &passwd, std::istream &is, std::ostream &os)
string_vector mput_directory(const std::string &base, const std::string &directory)
octave_idx_type numel(void) const
Number of elements in the array.
write the output to stdout if nargout is
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
void cwd(const std::string &path)
void rename(const std::string &oldname, const std::string &newname)
std::ostream * curr_ostream
static int read_data(void *buffer, size_t size, size_t nmemb, void *streamp)
std::istream * curr_istream
OCTAVE_EXPORT octave_value_list directory