mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-07 15:50:57 +03:00
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!
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<Request>(PacketType.INIT).putInt(clientVersion));
|
||||
transmit(new SFTPPacket<Request>(PacketType.INIT).putInt(MAX_SUPPORTED_VERSION));
|
||||
|
||||
final SFTPPacket<Response> 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());
|
||||
|
||||
Reference in New Issue
Block a user