[JSch-users] mods to jsc 0.0.13
Status: Alpha
Brought to you by:
ymnk
From: <gra...@nt...> - 2003-02-06 15:35:41
|
Thanks for the fixes/changes betwen 0.0.11 and 0.0.13 was even worth the effort of re-porting my code :-) ...I'd looked a refactoring ATTRS but looked too much effort ... this is why my Ssh_exp_name is done as a subclass (to match 0.0.11) oh well! Starting with jsc-0.0.13 as my startiing point: First of all ... whoever the (other) emacs user is ... /* -*-mode:java; c-basic-offset:2; -*- */ Havn't you discovered JDE mode yet!! It's wonderful (the C-c C-V C-z just blows me away, not to mention C-c C-v C-w :-) the above line stops it starting up ... gurr :-) There are some warnings you get if you use (the more strict) jikes (free from IBM) to compile your code (version 1.13) sunprototype1 $ sh buildit.sh Issued 1 semantic warning compiling "com/jcraft/jsch/Channel.java": 233. catch(Exception e){ <---------> *** Caution: This try block cannot throw a "checked exception" (JLS section 14.7) that can be caught here. You may have intended to catch a RuntimeException instead of an Exception. Issued 1 semantic warning compiling "com/jcraft/jsch/ChannelDirectTCPIP.java": 48. catch(Exception e){ <---------> *** Caution: This try block cannot throw a "checked exception" (JLS section 14.7) that can be caught here. You may have intended to catch a RuntimeException instead of an Exception. Here are the diffs I made to 0.0.13 (moving my changes from 0.0.11) .. my aim is that I need a way to do ls(1) on remote machines and get the same data back from DOS, Solaris, Linux, MVS etc. In the example I've added (SftpPubKey.java, not here) three directory commands exist, which work in seperate ways ls dir ls1 A better approach might be the mode command from ftp ... but both these are extensions to (breaks with) the sftp almost-RFC ... maybe we should suggest something. (ref page 22, section 7 SHH_FXP_NAME "...clients SHOULD NOT attempt to parse the longname ..." I'll send my SftpPubKey.java example separately. .... oops just realised I've not ported my mods the the Sftp.java example ... I'll add these to the end of this mail sunprototype1 $ dircmp -d -s -w 150 /tmp/orig/jsch-0.0.13 jsch-0.0.13 Feb 6 14:49 2003 /tmp/orig/jsch-0.0.13 only and jsch-0.0.13 only Page 1 ./examples/Sftp.jad ./examples/sftp.properties.linux ./examples/sftp.properties.solaris ./examples/SftpPubKey.java ./mod_classpath ./solaris_mod_classpath ./src/buildit.sh ./src/com/jcraft/jsch/JSch.java~ ./src/com/jcraft/jsch/KnownHosts.java~ Feb 6 14:49 2003 Comparison of /tmp/orig/jsch-0.0.13 jsch-0.0.13 Page 1 different ./src/com/jcraft/jsch/ChannelSftp.java different ./src/com/jcraft/jsch/SftpATTRS.java Feb 6 14:49 2003 diff of ./src/com/jcraft/jsch/ChannelSftp.java in /tmp/orig/jsch-0.0.13 and jsch-0.0.13 Page 1 1c1 < /* -*-mode:java; c-basic-offset:2; -*- */ --- > /* -*-mode:java; mode: jde; c-basic-offset:2; -*- */ 385c385,392 < str=buf.getString(); --- > > String filename; > String longname; > SftpATTRS attrs; > > > str=buf.getString(); > filename = new String(str); 387c394,396 < str=buf.getString(); // logname --- > > str=buf.getString(); // logname > longname = new String(str); 389d397 < v.addElement(new String(str)); 391c399,405 < SftpATTRS.getATTR(buf); --- > > // v.addElement(new String(str)); GPV: Old style way of doing things > > attrs=SftpATTRS.getATTR(buf); > > v.addElement(new Ssh_exp_name(filename, longname, attrs )); // GPV: New style way of doing things > 404c418 < count--; --- > count--; 762a777,781 > /* > * Class: Ssh_exp_name > * > * Represents the result of a query about filenames (e.g. FXP_OPENDIR+ FXP_READDIR ) > */ 763a783,817 > public static class Ssh_exp_name { > > private String filename; > private String longname; > private SftpATTRS attrs; > > > Ssh_exp_name(String filename, > String longname, > SftpATTRS attrs) { > > setFilename(filename); Feb 6 14:49 2003 diff of ./src/com/jcraft/jsch/ChannelSftp.java in /tmp/orig/jsch-0.0.13 and jsch-0.0.13 Page 2 > setLongname(longname); > setAttrs(attrs); > } > > > public String getFilename() {return filename;}; > public void setFilename(String filename) {this.filename = filename;}; > > public String getLongname() {return longname;}; > public void setLongname(String longname) {this.longname = longname;}; > > public SftpATTRS getAttrs() {return attrs;}; > public void setAttrs(SftpATTRS attrs) {this.attrs = attrs;}; > > > public String toString() { > > return (attrs.toString()+" "+filename); > > } > > } > Feb 6 14:49 2003 diff of ./src/com/jcraft/jsch/SftpATTRS.java in /tmp/orig/jsch-0.0.13 and jsch-0.0.13 Page 1 1c1 < /* -*-mode:java; c-basic-offset:2; -*- */ --- > /* -*-mode:java; mode: jde; c-basic-offset:2; -*- */ 23a24,26 > import java.text.SimpleDateFormat; > import java.util.Date; > import java.text.DateFormat; 159,164c162,248 < public String toString(){ < return (((flags&SSH_FILEXFER_ATTR_SIZE)!=0) ? ("size:"+size+" ") : "")+ < (((flags&SSH_FILEXFER_ATTR_UIDGID)!=0) ? ("uid:"+uid+",gid:"+gid+" ") : "")+ < (((flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0) ? ("permissions:0x"+Integer.toHexString(permissions)+" ") : "")+ < (((flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0) ? ("atime:"+atime+",mtime:"+mtime+" ") : "")+ < (((flags&SSH_FILEXFER_ATTR_EXTENDED)!=0) ? ("extended:?"+" ") : ""); --- > static final int S_ISUID = 04000; // set user ID on execution > static final int S_ISGID = 02000; // set group ID on execution > static final int S_ISVTX = 01000; // sticky bit ****** NOT DOCUMENTED ***** > > static final int S_IRUSR = 00400; // read by owner > static final int S_IWUSR = 00200; // write by owner > static final int S_IXUSR = 00100; // execute/search by owner > static final int S_IREAD = 00400; // read by owner > static final int S_IWRITE= 00200; // write by owner > static final int S_IEXEC = 00100; // execute/search by owner > > static final int S_IRGRP = 00040; // read by group > static final int S_IWGRP = 00020; // write by group > static final int S_IXGRP = 00010; // execute/search by group > > static final int S_IROTH = 00004; // read by others > static final int S_IWOTH = 00002; // write by others > static final int S_IXOTH = 00001; // execute/search by others > > > String getPermissionsString() { > StringBuffer buf = new StringBuffer(10); > > if (isDir()) > buf.append('d'); > else > buf.append('-'); > > > > if ((permissions & S_IRUSR) != 0) > buf.append('r'); > else > buf.append('-'); > > if ((permissions & S_IWUSR) != 0) > buf.append('w'); > else > buf.append('-'); > Feb 6 14:49 2003 diff of ./src/com/jcraft/jsch/SftpATTRS.java in /tmp/orig/jsch-0.0.13 and jsch-0.0.13 Page 2 > if ((permissions & S_ISUID) != 0) > buf.append('s'); > else if ((permissions & S_IXUSR) != 0) > buf.append('x'); > else > buf.append('-'); > > > > if ((permissions & S_IRGRP) != 0) > buf.append('r'); > else > buf.append('-'); > > if ((permissions & S_IWGRP) != 0) > buf.append('w'); > else > buf.append('-'); > > if ((permissions & S_ISGID) != 0) > buf.append('s'); > else if ((permissions & S_IXGRP) != 0) > buf.append('x'); > else > buf.append('-'); > > > > > if ((permissions & S_IROTH) != 0) > buf.append('r'); > else > buf.append('-'); > > if ((permissions & S_IWOTH) != 0) > buf.append('w'); > else > buf.append('-'); > > if ((permissions & S_IXOTH) != 0) > buf.append('x'); > else > buf.append('-'); > > > return (buf.toString()); > 167c251,281 < } --- > > public String getAtimeString(){ > DateFormat locale = new SimpleDateFormat(); > > return (locale.format(new Date(atime))); > } Feb 6 14:49 2003 diff of ./src/com/jcraft/jsch/SftpATTRS.java in /tmp/orig/jsch-0.0.13 and jsch-0.0.13 Page 3 > > > public String getMtimeString(){ > Date date= new Date(((long)mtime)*1000); > > return (date.toString()); > } > > > > public String toString() { > > return (getPermissionsString()+" "+getUId()+" "+getGId()+" "+getSize()+" "+getMtimeString()); > > } > > // public String toString(){ > // return (((flags&SSH_FILEXFER_ATTR_SIZE)!=0) ? ("size:"+size+" ") : "")+ > // (((flags&SSH_FILEXFER_ATTR_UIDGID)!=0) ? ("uid:"+uid+",gid:"+gid+" ") : "")+ > // (((flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0) ? ("permissions:0x"+Integer.toHexString(permissions)+" ") : "")+ > // (((flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0) ? ("atime:"+atime+",mtime:"+mtime+" ") : "")+ > // (((flags&SSH_FILEXFER_ATTR_EXTENDED)!=0) ? ("extended:?"+" ") : ""); > > } > ========== heres the missed out port of Sftp.java sunprototype1 $ diff /tmp/orig/jsch-0.0.13/examples/Sftp.java Sftp.java 133c133,140 < out.println(vv.elementAt(ii)); --- > Object obj=vv.elementAt(ii); > if (obj instanceof com.jcraft.jsch.ChannelSftp.Ssh_exp_name ) > out.println(((com.jcraft.jsch.ChannelSftp.Ssh_exp_name)obj).getLongname()); > else if (obj instanceof java.lang.String ) > out.println(obj); > else > throw new Exception("opps, got an odd type back"); > // out.println(vv.elementAt(ii)); sunprototype1 $ I'll send the total sources (including new example) to js...@jc... -- A slipping gear could let your M203 grenade launcher fire when you least expect it. That would make you quite unpopular in what's left of your unit. -- In the August 1993 issue, page 9, of "PS magazine", the Army's magazine of preventive maintenance Graeme The contents of this email and any attachments are sent for the personal attention of the addressee(s) only and may be confidential. If you are not the intended addressee, any use, disclosure or copying of this email and any attachments is unauthorised - please notify the sender by return and delete the message. Any representations or commitments expressed in this email are subject to contract. ntl Group Limited |