27 #if defined (HAVE_CONFIG_H) 112 int nargin = args.length ();
128 method = args(2).xstring_value (
"urlwrite: METHOD must be a string");
131 error (R
"(urlwrite: METHOD must be "get" or "post")"); 133 param = args(3).xcellstr_value ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell array of strings");
136 error (
"urlwrite: number of elements in PARAM must be even");
145 std::ofstream
ofile (
filename.c_str (), std::ios::out | std::ios::binary);
148 error (
"urlwrite: unable to open file");
158 if (! url_xfer.is_valid ())
159 error (
"support for URL transfers was disabled when Octave was built");
165 if (url_xfer.good ())
170 if (url_xfer.good ())
173 retval =
ovl (
"",
false, url_xfer.lasterror ());
176 if (
nargout < 2 && ! url_xfer.good ())
177 error (
"urlwrite: %s", url_xfer.lasterror ().c_str ());
226 int nargin = args.length ();
232 std::string url = args(0).xstring_value (
"urlread: URL must be a string");
239 method = args(1).xstring_value (
"urlread: METHOD must be a string");
242 error (R
"(urlread: METHOD must be "get" or "post")"); 244 param = args(2).xcellstr_value ("urlread: parameters (PARAM) for get and post requests must be given as a cell array of strings");
247 error (
"urlread: number of elements in PARAM must be even");
250 std::ostringstream buf;
255 error (
"support for URL transfers was disabled when Octave was built");
281 int nargin = args.length ();
286 std::string host = args(0).xstring_value (
"__ftp__: HOST must be a string");
289 ? args(1).xstring_value (
"__ftp__: USER must be a string")
293 ? args(2).xstring_value (
"__ftp__: PASSWD must be a string")
310 if (args.length () != 1)
311 error (
"__ftp_pwd__: incorrect number of arguments");
318 error (
"__ftp_pwd__: invalid ftp handle");
320 return ovl (url_xfer.
pwd ());
329 int nargin = args.length ();
332 error (
"__ftp_cwd__: incorrect number of arguments");
336 path = args(1).xstring_value (
"__ftp_cwd__: PATH must be a string");
343 error (
"__ftp_cwd__: invalid ftp handle");
356 if (args.length () != 1)
357 error (
"__ftp_dir__: incorrect number of arguments");
364 error (
"__ftp_dir__: invalid ftp handle");
406 fileisdir (
i) = fisdir;
407 filectime (
i) = ctime (&ftime);
408 filesize (
i) = fsize;
409 filedatenum (
i) =
double (ftime);
412 st.
assign (
"date", filectime);
413 st.
assign (
"bytes", filesize);
414 st.
assign (
"isdir", fileisdir);
415 st.
assign (
"datenum", filedatenum);
424 DEFMETHOD (__ftp_ascii__, interp, args, ,
430 if (args.length () != 1)
431 error (
"__ftp_ascii__: incorrect number of arguments");
438 error (
"__ftp_ascii__: invalid ftp handle");
445 DEFMETHOD (__ftp_binary__, interp, args, ,
451 if (args.length () != 1)
452 error (
"__ftp_binary__: incorrect number of arguments");
459 error (
"__ftp_binary__: invalid ftp handle");
466 DEFMETHOD (__ftp_close__, interp, args, ,
472 if (args.length () != 1)
473 error (
"__ftp_close__: incorrect number of arguments");
480 error (
"__ftp_close__: invalid ftp handle");
493 if (args.length () != 1)
494 error (
"__ftp_mode__: incorrect number of arguments");
501 error (
"__ftp_binary__: invalid ftp handle");
503 return ovl (url_xfer.
is_ascii () ?
"ascii" :
"binary");
506 DEFMETHOD (__ftp_delete__, interp, args, ,
512 if (args.length () != 2)
513 error (
"__ftp_delete__: incorrect number of arguments");
515 std::string file = args(1).xstring_value (
"__ftp_delete__: FILE must be a string");
522 error (
"__ftp_delete__: invalid ftp handle");
529 DEFMETHOD (__ftp_rmdir__, interp, args, ,
535 if (args.length () != 2)
536 error (
"__ftp_rmdir__: incorrect number of arguments");
538 std::string dir = args(1).xstring_value (
"__ftp_rmdir__: DIR must be a string");
545 error (
"__ftp_rmdir__: invalid ftp handle");
547 url_xfer.
rmdir (dir);
552 DEFMETHOD (__ftp_mkdir__, interp, args, ,
558 if (args.length () != 2)
559 error (
"__ftp_mkdir__: incorrect number of arguments");
561 std::string dir = args(1).xstring_value (
"__ftp_mkdir__: DIR must be a string");
568 error (
"__ftp_mkdir__: invalid ftp handle");
570 url_xfer.
mkdir (dir);
575 DEFMETHOD (__ftp_rename__, interp, args, ,
581 if (args.length () != 3)
582 error (
"__ftp_rename__: incorrect number of arguments");
584 std::string oldname = args(1).xstring_value (
"__ftp_rename__: OLDNAME must be a string");
585 std::string newname = args(2).xstring_value (
"__ftp_rename__: NEWNAME must be a string");
592 error (
"__ftp_rename__: invalid ftp handle");
594 url_xfer.
rename (oldname, newname);
605 if (args.length () != 2)
606 error (
"__ftp_mput__: incorrect number of arguments");
608 std::string pat = args(1).xstring_value (
"__ftp_mput__: PATTERN must be a string");
615 error (
"__ftp_mput__: invalid ftp handle");
629 error (
"__ftp__mput: file does not exist");
635 if (! url_xfer.
good ())
641 std::ifstream ifile (
file.c_str (), std::ios::in | std::ios::binary);
643 if (! ifile.is_open ())
644 error (
"__ftp_mput__: unable to open file");
650 if (! url_xfer.
good ())
658 return ovl (file_list);
670 int nargin = args.length ();
673 error (
"__ftp_mget__: incorrect number of arguments");
675 std::string file = args(1).xstring_value (
"__ftp_mget__: PATTERN must be a string");
679 if (
nargin == 3 && ! args(2).isempty ())
687 error (
"__ftp_mget__: invalid ftp handle");
709 std::ofstream
ofile ((target + sv(
i)).c_str (),
713 if (!
ofile.is_open ())
714 error (
"__ftp_mget__: unable to open file");
724 if (url_xfer.
good ())
728 if (! url_xfer.
good ())
734 error (
"__ftp_mget__: file not found");
url_handle make_url_handle(const std::string &host, const std::string &user, const std::string &passwd, std::ostream &os)
bool is_valid(void) const
For example cd octave end example noindent changes the current working directory to file
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
void assign(const std::string &k, const Cell &val)
url_handle lookup(double val)
std::string lasterror(void) const
int unlink(const std::string &name)
OCTINTERP_API void print_usage(void)
void mkdir(const std::string &path)
void rename(const std::string &oldname, const std::string &newname)
std::string tilde_expand(const std::string &name)
void add_fcn(void(*fcn)(void))
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
void put(const std::string &file, std::istream &is)
std::string dir_sep_str(void)
void mget_directory(const std::string &directory, const std::string &target)
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
string_vector mput_directory(const std::string &base, const std::string &directory)
void free(const url_handle &h)
string_vector & append(const std::string &s)
void rmdir(const std::string &path)
void get_fileinfo(const std::string &filename, double &filesize, time_t &filetime, bool &fileisdir)
Array< std::string > param
is longer than or if then or only for unique occurrences of the complete pattern(false). The default is true. If a cell array of strings ar
void get(const std::string &file, std::ostream &os)
octave::unwind_protect frame
bool is_ascii(void) const
std::ofstream ofile(filename.c_str(), std::ios::out|std::ios::binary)
void cwd(const std::string &path)
void http_action(const Array< std::string > ¶m, const std::string &action)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
void del(const std::string &file)
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)
url_transfer get_object(double val)
octave::sys::file_stat fs(filename)
octave_idx_type numel(void) const
Number of elements in the array.
Vector representing the dimensions (size) of an Array.
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