26 #if defined (HAVE_CONFIG_H)
68 int nargin = args.length ();
70 if (nargin < 1 || nargin > 3)
73 std::string host = args(0).xstring_value (
"__ftp__: HOST must be a string");
75 std::string user = (nargin > 1)
76 ? args(1).xstring_value (
"__ftp__: USER must be a string")
79 std::string passwd = (nargin > 2)
80 ? args(2).xstring_value (
"__ftp__: PASSWD must be a string")
97 if (args.length () != 1)
98 error (
"__ftp_pwd__: incorrect number of arguments");
105 error (
"__ftp_pwd__: invalid ftp handle");
107 return ovl (url_xfer.
pwd ());
116 int nargin = args.length ();
118 if (nargin != 1 && nargin != 2)
119 error (
"__ftp_cwd__: incorrect number of arguments");
121 std::string
path =
"";
123 path = args(1).xstring_value (
"__ftp_cwd__: PATH must be a string");
130 error (
"__ftp_cwd__: invalid ftp handle");
137 DEFMETHOD (__ftp_dir__, interp, args, nargout,
143 if (args.length () != 1)
144 error (
"__ftp_dir__: incorrect number of arguments");
151 error (
"__ftp_dir__: invalid ftp handle");
193 fileisdir (i) = fisdir;
194 filectime (i) = ctime (&ftime);
195 filesize (i) = fsize;
196 filedatenum (i) = double (ftime);
199 st.
assign (
"date", filectime);
200 st.
assign (
"bytes", filesize);
201 st.
assign (
"isdir", fileisdir);
202 st.
assign (
"datenum", filedatenum);
211 DEFMETHOD (__ftp_ascii__, interp, args, ,
217 if (args.length () != 1)
218 error (
"__ftp_ascii__: incorrect number of arguments");
225 error (
"__ftp_ascii__: invalid ftp handle");
232 DEFMETHOD (__ftp_binary__, interp, args, ,
238 if (args.length () != 1)
239 error (
"__ftp_binary__: incorrect number of arguments");
246 error (
"__ftp_binary__: invalid ftp handle");
253 DEFMETHOD (__ftp_close__, interp, args, ,
259 if (args.length () != 1)
260 error (
"__ftp_close__: incorrect number of arguments");
267 error (
"__ftp_close__: invalid ftp handle");
280 if (args.length () != 1)
281 error (
"__ftp_mode__: incorrect number of arguments");
288 error (
"__ftp_binary__: invalid ftp handle");
290 return ovl (url_xfer.
is_ascii () ?
"ascii" :
"binary");
293 DEFMETHOD (__ftp_delete__, interp, args, ,
299 if (args.length () != 2)
300 error (
"__ftp_delete__: incorrect number of arguments");
302 std::string file = args(1).xstring_value (
"__ftp_delete__: FILE must be a string");
309 error (
"__ftp_delete__: invalid ftp handle");
316 DEFMETHOD (__ftp_rmdir__, interp, args, ,
322 if (args.length () != 2)
323 error (
"__ftp_rmdir__: incorrect number of arguments");
325 std::string dir = args(1).xstring_value (
"__ftp_rmdir__: DIR must be a string");
332 error (
"__ftp_rmdir__: invalid ftp handle");
334 url_xfer.
rmdir (dir);
339 DEFMETHOD (__ftp_mkdir__, interp, args, ,
345 if (args.length () != 2)
346 error (
"__ftp_mkdir__: incorrect number of arguments");
348 std::string dir = args(1).xstring_value (
"__ftp_mkdir__: DIR must be a string");
355 error (
"__ftp_mkdir__: invalid ftp handle");
357 url_xfer.
mkdir (dir);
362 DEFMETHOD (__ftp_rename__, interp, args, ,
368 if (args.length () != 3)
369 error (
"__ftp_rename__: incorrect number of arguments");
371 std::string oldname = args(1).xstring_value (
"__ftp_rename__: OLDNAME must be a string");
372 std::string newname = args(2).xstring_value (
"__ftp_rename__: NEWNAME must be a string");
379 error (
"__ftp_rename__: invalid ftp handle");
381 url_xfer.
rename (oldname, newname);
386 DEFMETHOD (__ftp_mput__, interp, args, nargout,
392 if (args.length () != 2)
393 error (
"__ftp_mput__: incorrect number of arguments");
395 std::string pat = args(1).xstring_value (
"__ftp_mput__: PATTERN must be a string");
402 error (
"__ftp_mput__: invalid ftp handle");
411 std::string file = files(i);
416 error (
"__ftp__mput: file does not exist");
422 if (! url_xfer.
good ())
430 std::ios::in | std::ios::binary);
432 if (! ifile.is_open ())
433 error (
"__ftp_mput__: unable to open file");
435 url_xfer.
put (file, ifile);
439 if (! url_xfer.
good ())
447 return ovl (file_list);
459 int nargin = args.length ();
461 if (nargin != 2 && nargin != 3)
462 error (
"__ftp_mget__: incorrect number of arguments");
464 std::string file = args(1).xstring_value (
"__ftp_mget__: PATTERN must be a string");
468 if (nargin == 3 && ! args(2).isempty ())
469 target = args(2).xstring_value (
"__ftp_mget__: TARGET must be a string")
477 error (
"__ftp_mget__: invalid ftp handle");
485 if (pattern.
match (sv(i)))
501 std::ios::out | std::ios::binary);
503 if (! ofile.is_open ())
504 error (
"__ftp_mget__: unable to open file");
510 url_xfer.
get (sv(i), ofile);
514 if (url_xfer.
good ())
518 if (! url_xfer.
good ())
524 error (
"__ftp_mget__: file not found");
static void delete_file(const std::string &file)
Vector representing the dimensions (size) of an Array.
string_vector glob(void) const
bool match(const std::string &str) const
void add_fcn(void(*fcn)(Params...), Args &&... args)
url_handle lookup(double val)
url_transfer get_object(double val)
void free(const url_handle &h)
url_handle make_url_handle(const std::string &host, const std::string &user, const std::string &passwd, std::ostream &os)
void mget_directory(const std::string &directory, const std::string &target)
std::string lasterror(void) const
void cwd(const std::string &path)
string_vector mput_directory(const std::string &base, const std::string &directory)
void rename(const std::string &oldname, const std::string &newname)
bool is_valid(void) const
void mkdir(const std::string &path)
bool is_ascii(void) const
void rmdir(const std::string &path)
void put(const std::string &file, std::istream &is)
void del(const std::string &file)
void get(const std::string &file, std::ostream &os)
void get_fileinfo(const std::string &filename, double &filesize, time_t &filetime, bool &fileisdir)
void assign(const std::string &k, const Cell &val)
string_vector & append(const std::string &s)
octave_idx_type numel(void) const
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
void error(const char *fmt,...)
std::string dir_sep_str(void)
std::string tilde_expand(const std::string &name)
std::ifstream ifstream(const std::string &filename, const std::ios::openmode mode)
int unlink(const std::string &name)
std::ofstream ofstream(const std::string &filename, const std::ios::openmode mode)
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.