octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FTP objects


From: David Bateman
Subject: Re: FTP objects
Date: Tue, 01 Dec 2009 22:25:30 +0100
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706)

Judd Storrs wrote:
Here are v6 and v7.3 versions. The v6 refuses to load in octave, but
the v7.3 version loads somewhat octave as a struct with numeric ascii
vectors instead of strings.

char(fp.password)
char(fp.username)

seem to work for decoding them.
Thanks, this is interesting but annoying.. The jobject is the same as my curlhandle and is empty in the files you gave and so I can just basically ignore this field. However the "type" and "remotePwd" fields are java stringBuffer objects and Octave can't handle these so I can't use or save them. I therefore don't expect to be able to save an Octave FTP object and load it in matlab. However, if I ignore the type and the remotePwd I can recreate a matlab FTP object in Octave, just with the wrong remote path. The attached patch, that I pushed, does this.

Anyone know of a simple way to read/write matlab java stringBuffer objects?

D.


# HG changeset patch
# User David Bateman <address@hidden>
# Date 1259702015 -3600
# Node ID 4bf50a7d533b10eb2964c09101c391ed88d78782
# Parent  1aeb39118764056f7817a9592375c3bb72b27a80
fix for FTP object constructor. Allow basic operation with matlab FTP objects

diff --git a/scripts/@ftp/display.m b/scripts/@ftp/display.m
--- 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
diff --git a/scripts/@ftp/ftp.m b/scripts/@ftp/ftp.m
--- 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
diff --git a/scripts/@ftp/loadobj.m b/scripts/@ftp/loadobj.m
--- 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
diff --git a/scripts/ChangeLog b/scripts/ChangeLog
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,11 @@
+2009-12-01  David Bateman  <address@hidden>
+
+       * @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  <address@hidden>
 
        * plot/private/__axes_limits__.m:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]