From 974e88efb49548fbcd5eae085181fa3c3fa47181 Mon Sep 17 00:00:00 2001 From: Shikhar Bhushan Date: Fri, 6 Aug 2010 22:29:43 +0100 Subject: [PATCH] no need to actually have API client specify sftp protocol version, so long as all versions < MAX_SUPPORTED_VERSIONS are supported. which is true for now! --- src/main/java/net/schmizz/sshj/SSHClient.java | 15 +-------------- .../java/net/schmizz/sshj/sftp/SFTPEngine.java | 17 ++++------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/schmizz/sshj/SSHClient.java b/src/main/java/net/schmizz/sshj/SSHClient.java index 6ccdcf20..0e98f9c3 100644 --- a/src/main/java/net/schmizz/sshj/SSHClient.java +++ b/src/main/java/net/schmizz/sshj/SSHClient.java @@ -593,21 +593,8 @@ public class SSHClient */ public SFTPClient newSFTPClient() throws IOException { - return newSFTPClient(SFTPEngine.MAX_SUPPORTED_VERSION); - } - - /** - * @param version the protocol version to use - * - * @return Instantiated {@link SFTPClient} implementation. - * - * @throws IOException if there is an error starting the {@code sftp} subsystem - * @see StatefulSFTPClient - */ - public SFTPClient newSFTPClient(int version) - throws IOException { assert isConnected() && isAuthenticated(); - return new SFTPClient(new SFTPEngine(this, version).init()); + return new SFTPClient(new SFTPEngine(this).init()); } /** diff --git a/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java b/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java index 1d21b04f..bce7bf0e 100644 --- a/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java +++ b/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java @@ -41,7 +41,6 @@ public class SFTPEngine protected volatile int timeout = DEFAULT_TIMEOUT; - protected final int clientVersion; protected final Subsystem sub; protected final PacketReader reader; protected final OutputStream out; @@ -52,14 +51,6 @@ public class SFTPEngine public SFTPEngine(SessionFactory ssh) throws SSHException { - this(ssh, MAX_SUPPORTED_VERSION); - } - - public SFTPEngine(SessionFactory ssh, int clientVersion) - throws SSHException { - if (clientVersion > MAX_SUPPORTED_VERSION) - throw new SFTPException("Max. supported protocol version is: " + MAX_SUPPORTED_VERSION); - this.clientVersion = clientVersion; sub = ssh.startSession().startSubsystem("sftp"); out = sub.getOutputStream(); reader = new PacketReader(this); @@ -67,7 +58,7 @@ public class SFTPEngine public SFTPEngine init() throws IOException { - transmit(new SFTPPacket(PacketType.INIT).putInt(clientVersion)); + transmit(new SFTPPacket(PacketType.INIT).putInt(MAX_SUPPORTED_VERSION)); final SFTPPacket response = reader.readPacket(); @@ -76,9 +67,9 @@ public class SFTPEngine throw new SFTPException("Expected INIT packet, received: " + type); operativeVersion = response.readInt(); - log.info("Client version {}, server version {}", clientVersion, operativeVersion); - if (clientVersion < operativeVersion) - throw new SFTPException("Server reported protocol version: " + operativeVersion); + log.info("Server version {}", operativeVersion); + if (MAX_SUPPORTED_VERSION < operativeVersion) + throw new SFTPException("Server reported incompatible protocol version: " + operativeVersion); while (response.available() > 0) serverExtensions.put(response.readString(), response.readString());