public class SftpStreamProxy
extends java.lang.Object
implements com.jcraft.jsch.Proxy
Use a command on the proxy that will forward the SSH stream to the target host and port.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BASH_TCP_COMMAND
Command format using bash built-in TCP stream.
|
private com.jcraft.jsch.ChannelExec |
channel |
private java.lang.String |
commandFormat
Command pattern to execute on the proxy host.
|
static java.lang.String |
NETCAT_COMMAND
Command format using netcat command.
|
private java.lang.String |
proxyHost
Hostname used to connect to the proxy host.
|
private FileSystemOptions |
proxyOptions
The options for connection.
|
private java.lang.String |
proxyPassword
The password to be used for connection.
|
private int |
proxyPort
Port used to connect to the proxy host.
|
private java.lang.String |
proxyUser
Username used to connect to the proxy host.
|
private com.jcraft.jsch.Session |
session |
Constructor and Description |
---|
SftpStreamProxy(java.lang.String commandFormat,
java.lang.String proxyUser,
java.lang.String proxyHost,
int proxyPort,
java.lang.String proxyPassword,
FileSystemOptions proxyOptions)
Creates a stream proxy.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
connect(com.jcraft.jsch.SocketFactory socketFactory,
java.lang.String targetHost,
int targetPort,
int timeout) |
java.io.InputStream |
getInputStream() |
java.io.OutputStream |
getOutputStream() |
java.net.Socket |
getSocket() |
public static final java.lang.String BASH_TCP_COMMAND
public static final java.lang.String NETCAT_COMMAND
private com.jcraft.jsch.ChannelExec channel
private final java.lang.String commandFormat
When run, the command output should be forwarded to the target host and port, and its input should be forwarded from the target host and port.
The command will be created for each host/port pair by using String.format(String, Object...) with two objects: the target host name (String) and the target port (Integer).
Here are two examples (that can be easily used by using the static members of this class):
nc -q 0 %s %d
to use the netcat command (NETCAT_COMMAND)/bin/bash -c 'exec 3<>/dev/tcp/%s/%d; cat <&3 & cat >&3; kill $!
will use bash built-in TCP
stream, which can be useful when there is no netcat available. (BASH_TCP_COMMAND)private final java.lang.String proxyHost
private final FileSystemOptions proxyOptions
private final java.lang.String proxyPassword
private final int proxyPort
private final java.lang.String proxyUser
private com.jcraft.jsch.Session session
public SftpStreamProxy(java.lang.String commandFormat, java.lang.String proxyUser, java.lang.String proxyHost, int proxyPort, java.lang.String proxyPassword, FileSystemOptions proxyOptions)
commandFormat
- A format string that will be used to create the command to execute on the proxy host using
String.format(String, Object...). Two parameters are given to the format command, the
target host name (String) and port (Integer).proxyUser
- The proxy userproxyPassword
- The proxy passwordproxyHost
- The proxy hostproxyPort
- The port to connect to on the proxyproxyOptions
- Options used when connecting to the proxypublic void close()
close
in interface com.jcraft.jsch.Proxy
public void connect(com.jcraft.jsch.SocketFactory socketFactory, java.lang.String targetHost, int targetPort, int timeout) throws java.lang.Exception
connect
in interface com.jcraft.jsch.Proxy
java.lang.Exception
public java.io.InputStream getInputStream()
getInputStream
in interface com.jcraft.jsch.Proxy
public java.io.OutputStream getOutputStream()
getOutputStream
in interface com.jcraft.jsch.Proxy
public java.net.Socket getSocket()
getSocket
in interface com.jcraft.jsch.Proxy