diff src/ch/ethz/ssh2/SFTPv6Client.java @ 308:42b15aaa7ac7 ganymed

merge
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:21:50 -0700
parents 071eccdff8ea
children
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/SFTPv6Client.java	Wed Jul 30 13:38:04 2014 -0700
+++ b/src/ch/ethz/ssh2/SFTPv6Client.java	Wed Jul 30 14:21:50 2014 -0700
@@ -25,7 +25,6 @@
             public void read(String packet) {
                 log.debug("Read packet " + packet);
             }
-
             public void write(String packet) {
                 log.debug("Write packet " + packet);
             }
@@ -39,29 +38,24 @@
 
     public SFTPv6FileAttributes fstat(SFTPFileHandle handle) throws IOException {
         int req_id = generateNextRequestID();
-
         TypesWriter tw = new TypesWriter();
         tw.writeString(handle.getHandle(), 0, handle.getHandle().length);
-
         sendMessage(Packet.SSH_FXP_FSTAT, req_id, tw.getBytes());
-
         byte[] resp = receiveMessage(34000);
-
         TypesReader tr = new TypesReader(resp);
-
         int t = tr.readByte();
         listener.read(Packet.forName(t));
+        int rep_id = tr.readUINT32();
 
-        int rep_id = tr.readUINT32();
-        if(rep_id != req_id) {
+        if (rep_id != req_id) {
             throw new RequestMismatchException();
         }
 
-        if(t == Packet.SSH_FXP_ATTRS) {
+        if (t == Packet.SSH_FXP_ATTRS) {
             return new SFTPv6FileAttributes(tr);
         }
 
-        if(t != Packet.SSH_FXP_STATUS) {
+        if (t != Packet.SSH_FXP_STATUS) {
             throw new PacketTypeException(t);
         }
 
@@ -73,29 +67,24 @@
 
     private SFTPv6FileAttributes statBoth(String path, int statMethod) throws IOException {
         int req_id = generateNextRequestID();
-
         TypesWriter tw = new TypesWriter();
         tw.writeString(path, this.getCharset());
-
         sendMessage(statMethod, req_id, tw.getBytes());
-
         byte[] resp = receiveMessage(34000);
-
         TypesReader tr = new TypesReader(resp);
-
         int t = tr.readByte();
         listener.read(Packet.forName(t));
+        int rep_id = tr.readUINT32();
 
-        int rep_id = tr.readUINT32();
-        if(rep_id != req_id) {
+        if (rep_id != req_id) {
             throw new RequestMismatchException();
         }
 
-        if(t == Packet.SSH_FXP_ATTRS) {
+        if (t == Packet.SSH_FXP_ATTRS) {
             return new SFTPv6FileAttributes(tr);
         }
 
-        if(t != Packet.SSH_FXP_STATUS) {
+        if (t != Packet.SSH_FXP_STATUS) {
             throw new PacketTypeException(t);
         }
 
@@ -117,49 +106,55 @@
     private List<SFTPv6DirectoryEntry> scanDirectory(byte[] handle) throws IOException {
         List<SFTPv6DirectoryEntry> files = new ArrayList<SFTPv6DirectoryEntry>();
 
-        while(true) {
+        while (true) {
             int req_id = generateNextRequestID();
-
             TypesWriter tw = new TypesWriter();
             tw.writeString(handle, 0, handle.length);
-
             sendMessage(Packet.SSH_FXP_READDIR, req_id, tw.getBytes());
-
             byte[] resp = receiveMessage(34000);
-
             TypesReader tr = new TypesReader(resp);
-
             int t = tr.readByte();
             listener.read(Packet.forName(t));
             int rep_id = tr.readUINT32();
-            if(rep_id != req_id) {
+
+            if (rep_id != req_id) {
                 throw new RequestMismatchException();
             }
-            if(t == Packet.SSH_FXP_NAME) {
+
+            if (t == Packet.SSH_FXP_NAME) {
                 int count = tr.readUINT32();
-                if(log.isDebugEnabled()) {
+
+                if (log.isDebugEnabled()) {
                     log.debug(String.format("Parsing %d name entries", count));
                 }
-                while(count > 0) {
+
+                while (count > 0) {
                     SFTPv6DirectoryEntry file = new SFTPv6DirectoryEntry();
                     file.filename = tr.readString(this.getCharset());
                     listener.read(file.filename);
                     file.attributes = new SFTPv6FileAttributes(tr);
-                    if(log.isDebugEnabled()) {
+
+                    if (log.isDebugEnabled()) {
                         log.debug(String.format("Adding file %s", file));
                     }
+
                     files.add(file);
                     count--;
                 }
+
                 continue;
             }
-            if(t != Packet.SSH_FXP_STATUS) {
+
+            if (t != Packet.SSH_FXP_STATUS) {
                 throw new PacketTypeException(t);
             }
+
             int errorCode = tr.readUINT32();
-            if(errorCode == ErrorCodes.SSH_FX_EOF) {
+
+            if (errorCode == ErrorCodes.SSH_FX_EOF) {
                 return files;
             }
+
             String errorMessage = tr.readString();
             listener.read(errorMessage);
             throw new SFTPException(errorMessage, errorCode);
@@ -168,29 +163,24 @@
 
     public final SFTPFileHandle openDirectory(String path) throws IOException {
         int req_id = generateNextRequestID();
-
         TypesWriter tw = new TypesWriter();
         tw.writeString(path, this.getCharset());
-
         sendMessage(Packet.SSH_FXP_OPENDIR, req_id, tw.getBytes());
-
         byte[] resp = receiveMessage(34000);
-
         TypesReader tr = new TypesReader(resp);
-
         int t = tr.readByte();
         listener.read(Packet.forName(t));
+        int rep_id = tr.readUINT32();
 
-        int rep_id = tr.readUINT32();
-        if(rep_id != req_id) {
+        if (rep_id != req_id) {
             throw new RequestMismatchException();
         }
 
-        if(t == Packet.SSH_FXP_HANDLE) {
+        if (t == Packet.SSH_FXP_HANDLE) {
             return new SFTPFileHandle(this, tr.readByteString());
         }
 
-        if(t != Packet.SSH_FXP_STATUS) {
+        if (t != Packet.SSH_FXP_STATUS) {
             throw new PacketTypeException(t);
         }
 
@@ -251,34 +241,28 @@
     @Override
     public SFTPFileHandle openFile(String filename, int flags, SFTPFileAttributes attr) throws IOException {
         int req_id = generateNextRequestID();
-
         TypesWriter tw = new TypesWriter();
         tw.writeString(filename, this.getCharset());
         tw.writeUINT32(AceMask.ACE4_READ_DATA | AceMask.ACE4_READ_ATTRIBUTES | AceMask.ACE4_READ_ACL | AceMask.ACE4_READ_NAMED_ATTRS
-                | AceMask.ACE4_WRITE_DATA | AceMask.ACE4_APPEND_DATA | AceMask.ACE4_WRITE_ATTRIBUTES | AceMask.ACE4_WRITE_ACL | AceMask.ACE4_WRITE_NAMED_ATTRS);
+                       | AceMask.ACE4_WRITE_DATA | AceMask.ACE4_APPEND_DATA | AceMask.ACE4_WRITE_ATTRIBUTES | AceMask.ACE4_WRITE_ACL | AceMask.ACE4_WRITE_NAMED_ATTRS);
         tw.writeUINT32(flags);
-
         tw.writeBytes(attr.toBytes());
-
         sendMessage(Packet.SSH_FXP_OPEN, req_id, tw.getBytes());
-
         byte[] resp = receiveMessage(34000);
-
         TypesReader tr = new TypesReader(resp);
-
         int t = tr.readByte();
         listener.read(Packet.forName(t));
+        int rep_id = tr.readUINT32();
 
-        int rep_id = tr.readUINT32();
-        if(rep_id != req_id) {
+        if (rep_id != req_id) {
             throw new RequestMismatchException();
         }
 
-        if(t == Packet.SSH_FXP_HANDLE) {
+        if (t == Packet.SSH_FXP_HANDLE) {
             return new SFTPFileHandle(this, tr.readByteString());
         }
 
-        if(t != Packet.SSH_FXP_STATUS) {
+        if (t != Packet.SSH_FXP_STATUS) {
             throw new PacketTypeException(t);
         }
 
@@ -291,32 +275,26 @@
     @Override
     public void createSymlink(String src, String target) throws IOException {
         int req_id = generateNextRequestID();
-
         TypesWriter tw = new TypesWriter();
         // new-link-path
         tw.writeString(src, this.getCharset());
         // existing-path
         tw.writeString(target, this.getCharset());
         tw.writeBoolean(true);
-
         sendMessage(Packet.SSH_FXP_LINK, req_id, tw.getBytes());
-
         expectStatusOKMessage(req_id);
     }
 
     @Override
     public void createHardlink(String src, String target) throws IOException {
         int req_id = generateNextRequestID();
-
         TypesWriter tw = new TypesWriter();
         // new-link-path
         tw.writeString(src, this.getCharset());
         // existing-path
         tw.writeString(target, this.getCharset());
         tw.writeBoolean(false);
-
         sendMessage(Packet.SSH_FXP_LINK, req_id, tw.getBytes());
-
         expectStatusOKMessage(req_id);
     }
 }