changeset 9897:4bf50a7d533b

fix for FTP object constructor. Allow basic operation with matlab FTP objects
author David Bateman <dbateman@free.fr>
date Tue, 01 Dec 2009 22:13:35 +0100
parents 1aeb39118764
children 1ee24979591e
files scripts/@ftp/display.m scripts/@ftp/ftp.m scripts/@ftp/loadobj.m scripts/ChangeLog
diffstat 4 files changed, 39 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/@ftp/display.m
+++ b/scripts/@ftp/display.m
@@ -16,7 +16,7 @@
 function display (obj)
   printf ("FTP Object\n");
   printf (" host: %s\n", obj.host);
-  printf (" user: %s\n", obj.user);
+  printf (" user: %s\n", obj.username);
   printf ("  dir: %s\n", __ftp_pwd__ (obj.curlhandle));
   printf (" mode: %s\n", __ftp_mode__ (obj.curlhandle));
 endfunction
\ No newline at end of file
--- a/scripts/@ftp/ftp.m
+++ b/scripts/@ftp/ftp.m
@@ -22,11 +22,21 @@
 ## established FTP connection.
 ## @end deftypefn
 
-function obj = ftp (host, user = "anonymous", pass = "")
-  p.host = host;
-  p.user = user;
-  p.pass = pass;
-  p.curlhandle = tmpnam ("ftp-");
-  __ftp__ (p.curlhandle, host, user, pass);
-  obj = class (p, "ftp");
+function obj = ftp (host, username = "anonymous", password = "")
+  if (nargin == 0)
+    p.host = "";
+    p.username = username;
+    p.password = password;
+    p.curlhandle = tmpnam ("ftp-");
+    obj = class (p, "ftp");
+  elseif (nargin == 1 && strcmp (class (host), "ftp"))
+    obj = host;
+  else
+    p.host = host;
+    p.username = username;
+    p.password = password;
+    p.curlhandle = tmpnam ("ftp-");
+    __ftp__ (p.curlhandle, host, username, password);
+    obj = class (p, "ftp");
+  endif
 endfunction
--- a/scripts/@ftp/loadobj.m
+++ b/scripts/@ftp/loadobj.m
@@ -15,10 +15,19 @@
 
 function b = loadobj (a)
   b = a;
+  if (isfield (b, "jobject"))
+    b = rmfield (b, "jobject");
+  endif
   b.curlhandle = tmpnam ("ftp-");
-  __ftp__ (b.curlhandle, b.host, b.user, b.pass);
-  if (! isempty (b.dir))
-    __ftp_cwd__ (b.curlhandle, b.dir);
+  __ftp__ (b.curlhandle, b.host, b.username, b.password);
+  if (isfield (b, "dir"))
+    if (! isempty (b.dir))
+      __ftp_cwd__ (b.curlhandle, b.dir);
+    endif
+    b = rmfield (b, "dir")
+  elseif (isfield (b, "remotePwd"))
+    ## FIXME: Can we read matlab java stringBuffer objects?
+    warning ("can not change remote directory in loqded FTP object");
+    b = rmfield (b, "remotePwd");
   endif
-  b = rmfield (b, "dir")
 endfunction
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,11 @@
+2009-12-01  David Bateman  <dbateman@free.fr>
+
+	* @ftp/ftp.m: Treat empty constructor and construction from
+	another FTP object.
+	* @ftp/loadobj.m: Allow and remove the matlab specific fields
+	of FTP objects allowing matlab FTP objects to be loaded in Octave.
+	* @ftp/display.m: user -> username.
+
 2009-12-01  John W. Eaton  <jwe@octave.org>
 
 	* plot/private/__axes_limits__.m: