Top Description Inners Fields Constructors Methods
org.eclipse.jgit.transport.sshd

public Class SshdSession

extends Object
implements RemoteSession2
Class Inheritance
All Implemented Interfaces
org.eclipse.jgit.transport.RemoteSession2, org.eclipse.jgit.transport.RemoteSession
Static Imports
java.text.MessageFormat.format, org.apache.sshd.common.SshConstants.SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE, org.apache.sshd.sftp.SftpModuleProperties.SFTP_CHANNEL_OPEN_TIMEOUT

An implementation of RemoteSession based on Apache MINA sshd.
Since
5.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class

Field Summary

Modifier and TypeField and Description
private SshClient
private final CopyOnWriteArrayList<SessionCloseListener>
private static final Logger
private static final int
private ClientSession
private static final Pattern
private final URIish

Constructor Summary

AccessConstructor and Description
pack-priv
SshdSession(URIish uri, Supplier<SshClient> clientFactory)

Method Summary

Modifier and TypeMethod and Description
public void
addCloseListener(SessionCloseListener
to add
listener
)

Adds a SessionCloseListener to this session.

private void
close(Closeable toClose, Throwable error)

pack-priv void
connect(Duration timeout)

private ClientSession
connect(URIish target, List<URIish> jumps, SshFutureListener<CloseFuture> listener, Duration timeout, int depth)

private ClientSession
private List<URIish>
determineHops(List<URIish> currentHops, HostConfigEntry hostConfig, String host)

public void
disconnect()

Implements org.eclipse.jgit.transport.RemoteSession.disconnect.

Disconnects the remote session.

private void
public Process
exec(String
command to execute
commandName
,
int
timeout value, in seconds, for creating the remote process
timeout
)

Implements org.eclipse.jgit.transport.RemoteSession.exec.

Creates a new remote Process to execute the given command.

public Process
exec(String
command to execute
commandName
,
Map<String, String>
environment variables to pass on
environment
,
int
timeout value, in seconds, for creating the remote process
timeout
)

Implements org.eclipse.jgit.transport.RemoteSession2.exec.

Creates a new remote Process to execute the given command.

public FtpChannel
getFtpChannel()

Overrides default org.eclipse.jgit.transport.RemoteSession.getFtpChannel.

Obtain an FtpChannel to perform SFTP operations in this SshdSession.

private HostConfigEntry
getHostConfig(String username, String host, int port)

private void
private List<URIish>
public void
removeCloseListener(SessionCloseListener
to remove
listener
)

Removes the given listener; has no effect if the listener is not currently registered with this session.

private String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

clientback to summary
private SshClient client
listenersback to summary
private final CopyOnWriteArrayList<SessionCloseListener> listeners
LOGback to summary
private static final Logger LOG
MAX_DEPTHback to summary
private static final int MAX_DEPTH
sessionback to summary
private ClientSession session
SHORT_SSH_FORMATback to summary
private static final Pattern SHORT_SSH_FORMAT
uriback to summary
private final URIish uri

Constructor Detail

SshdSessionback to summary
pack-priv SshdSession(URIish uri, Supplier<SshClient> clientFactory)

Method Detail

addCloseListenerback to summary
public void addCloseListener(SessionCloseListener listener)

Adds a SessionCloseListener to this session. Has no effect if the given listener is already registered with this session.

Parameters
listener:SessionCloseListener

to add

closeback to summary
private void close(Closeable toClose, Throwable error)
connectback to summary
pack-priv void connect(Duration timeout) throws IOException
connectback to summary
private ClientSession connect(URIish target, List<URIish> jumps, SshFutureListener<CloseFuture> listener, Duration timeout, int depth) throws IOException
connectback to summary
private ClientSession connect(HostConfigEntry config, AttributeRepository context, Duration timeout) throws IOException
determineHopsback to summary
private List<URIish> determineHops(List<URIish> currentHops, HostConfigEntry hostConfig, String host) throws IOException
disconnectback to summary
public void disconnect()

Implements org.eclipse.jgit.transport.RemoteSession.disconnect.

Doc from org.eclipse.jgit.transport.RemoteSession.disconnect.

Disconnects the remote session.

Annotations
@Override
disconnectback to summary
private void disconnect(Throwable reason)
execback to summary
public Process exec(String commandName, int timeout) throws IOException

Implements org.eclipse.jgit.transport.RemoteSession.exec.

Doc from org.eclipse.jgit.transport.RemoteSession.exec.

Creates a new remote Process to execute the given command. The returned process's streams exist and are connected, and execution of the process is already started.

Parameters
commandName:String

command to execute

timeout:int

timeout value, in seconds, for creating the remote process

Returns:Process

a new remote process, already started

Annotations
@Override
Exceptions
IOException:
may be thrown in several cases. For example, on problems opening input or output streams or on problems connecting or communicating with the remote host. For the latter two cases, a TransportException may be thrown (a subclass of java.io.IOException).
execback to summary
public Process exec(String commandName, Map<String, String> environment, int timeout) throws IOException

Implements org.eclipse.jgit.transport.RemoteSession2.exec.

Doc from org.eclipse.jgit.transport.RemoteSession2.exec.

Creates a new remote Process to execute the given command. The returned process's streams exist and are connected, and execution of the process is already started.

Parameters
commandName:String

command to execute

environment:Map<String, String>

environment variables to pass on

timeout:int

timeout value, in seconds, for creating the remote process

Returns:Process

a new remote process, already started

Annotations
@Override
Exceptions
IOException:
may be thrown in several cases. For example, on problems opening input or output streams or on problems connecting or communicating with the remote host. For the latter two cases, a TransportException may be thrown (a subclass of java.io.IOException).
getFtpChannelback to summary
public FtpChannel getFtpChannel()

Overrides default org.eclipse.jgit.transport.RemoteSession.getFtpChannel.

Obtain an FtpChannel to perform SFTP operations in this SshdSession.

Returns:FtpChannel

Doc from org.eclipse.jgit.transport.RemoteSession.getFtpChannel.

the FtpChannel

Annotations
@Override
@NonNull
getHostConfigback to summary
private HostConfigEntry getHostConfig(String username, String host, int port) throws IOException
notifyCloseListenersback to summary
private void notifyCloseListeners()
parseProxyJumpback to summary
private List<URIish> parseProxyJump(String proxyJump) throws URISyntaxException
removeCloseListenerback to summary
public void removeCloseListener(SessionCloseListener listener)

Removes the given listener; has no effect if the listener is not currently registered with this session.

Parameters
listener:SessionCloseListener

to remove

withAuthLogback to summary
private String withAuthLog(String message, AuthenticationLogger authLog)
org.eclipse.jgit.transport.sshd back to summary

private Class SshdSession.SshdExecProcess

extends Process
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ChannelExec
private final String

Constructor Summary

AccessConstructor and Description
public
SshdExecProcess(ChannelExec channel, String commandName)

Method Summary

Modifier and TypeMethod and Description
public void
destroy()

Implements abstract java.lang.Process.destroy.

Kills the process.

public int
exitValue()

Implements abstract java.lang.Process.exitValue.

Returns the exit value for the process.

public InputStream
getErrorStream()

Implements abstract java.lang.Process.getErrorStream.

Returns the input stream connected to the error output of the process.

public InputStream
getInputStream()

Implements abstract java.lang.Process.getInputStream.

Returns the input stream connected to the normal output of the process.

public OutputStream
getOutputStream()

Implements abstract java.lang.Process.getOutputStream.

Returns the output stream connected to the normal input of the process.

public int
waitFor()

Implements abstract java.lang.Process.waitFor.

Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.

public boolean
waitFor(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Overrides java.lang.Process.waitFor.

Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated, or the specified waiting time elapses.

Inherited from java.lang.Process:
childrendescendantsdestroyForciblyerrorReadererrorReaderinfoinputReaderinputReaderisAliveonExitoutputWriteroutputWriterpidsupportsNormalTerminationtoHandlewaitFor

Field Detail

channelback to summary
private final ChannelExec channel
commandNameback to summary
private final String commandName

Constructor Detail

SshdExecProcessback to summary
public SshdExecProcess(ChannelExec channel, String commandName)

Method Detail

destroyback to summary
public void destroy()

Implements abstract java.lang.Process.destroy.

Doc from java.lang.Process.destroy.

Kills the process. Whether the process represented by this Process object is normally terminated or not is implementation dependent. Forcible process destruction is defined as the immediate termination of a process, whereas normal termination allows the process to shut down cleanly. If the process is not alive, no action is taken.

The java.util.concurrent.CompletableFuture from onExit is completed when the process has terminated.

Annotations
@Override
exitValueback to summary
public int exitValue()

Implements abstract java.lang.Process.exitValue.

Doc from java.lang.Process.exitValue.

Returns the exit value for the process.

Returns:int

the exit value of the process represented by this Process object. By convention, the value 0 indicates normal termination.

Annotations
@Override
getErrorStreamback to summary
public InputStream getErrorStream()

Implements abstract java.lang.Process.getErrorStream.

Doc from java.lang.Process.getErrorStream.

Returns the input stream connected to the error output of the process. The stream obtains data piped from the error output of the process represented by this Process object.

If the standard error of the process has been redirected using ProcessBuilder.redirectError or ProcessBuilder.redirectErrorStream then this method will return a null input stream.

Returns:InputStream

the input stream connected to the error output of the process

Annotations
@Override
getInputStreamback to summary
public InputStream getInputStream()

Implements abstract java.lang.Process.getInputStream.

Doc from java.lang.Process.getInputStream.

Returns the input stream connected to the normal output of the process. The stream obtains data piped from the standard output of the process represented by this Process object.

If the standard output of the process has been redirected using ProcessBuilder.redirectOutput then this method will return a null input stream.

Otherwise, if the standard error of the process has been redirected using ProcessBuilder.redirectErrorStream then the input stream returned by this method will receive the merged standard output and the standard error of the process.

Returns:InputStream

the input stream connected to the normal output of the process

Annotations
@Override
getOutputStreamback to summary
public OutputStream getOutputStream()

Implements abstract java.lang.Process.getOutputStream.

Doc from java.lang.Process.getOutputStream.

Returns the output stream connected to the normal input of the process. Output to the stream is piped into the standard input of the process represented by this Process object.

If the standard input of the process has been redirected using ProcessBuilder.redirectInput then this method will return a null output stream.

Returns:OutputStream

the output stream connected to the normal input of the process

Annotations
@Override
waitForback to summary
public int waitFor() throws InterruptedException

Implements abstract java.lang.Process.waitFor.

Doc from java.lang.Process.waitFor.

Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated. This method returns immediately if the process has already terminated. If the process has not yet terminated, the calling thread will be blocked until the process exits.

Returns:int

the exit value of the process represented by this Process object. By convention, the value 0 indicates normal termination.

Annotations
@Override
Exceptions
InterruptedException:
if the current thread is interrupted by another thread while it is waiting, then the wait is ended and an InterruptedException is thrown.
waitForback to summary
public boolean waitFor(long timeout, TimeUnit unit) throws InterruptedException

Overrides java.lang.Process.waitFor.

Doc from java.lang.Process.waitFor.

Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated, or the specified waiting time elapses.

If the process has already terminated then this method returns immediately with the value true. If the process has not terminated and the timeout value is less than, or equal to, zero, then this method returns immediately with the value false.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:boolean

true if the process has exited and false if the waiting time elapsed before the process has exited.

Annotations
@Override
Exceptions
InterruptedException:
if the current thread is interrupted while waiting.
org.eclipse.jgit.transport.sshd back to summary

private Class SshdSession.SshdFtpChannel

extends Object
implements FtpChannel
Class Inheritance
All Implemented Interfaces
org.eclipse.jgit.transport.FtpChannel

Field Summary

Modifier and TypeField and Description
private String
cwd

Current working directory.

private SftpClient

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private String
public void
cd(String
target directory
path
)

Implements org.eclipse.jgit.transport.FtpChannel.cd.

Changes the current remote directory.

public void
connect(int
for establishing the FTP connection
timeout
,
TimeUnit
of the timeout
unit
)

Implements org.eclipse.jgit.transport.FtpChannel.connect.

Connects the FtpChannel to the remote end.

public void
public InputStream
get(String
of the file to read
path
)

Implements org.eclipse.jgit.transport.FtpChannel.get.

Obtain an InputStream to read the contents of a remote file.

public boolean
isConnected()

Implements org.eclipse.jgit.transport.FtpChannel.isConnected.

Whether the FtpChannel is connected

public Collection<FtpChannel.DirEntry>
ls(String
of the directory to list
path
)

Implements org.eclipse.jgit.transport.FtpChannel.ls.

Lists contents of a remote directory

private <T> T
public void
mkdir(String
to create
path
)

Implements org.eclipse.jgit.transport.FtpChannel.mkdir.

Creates a directory on the remote file system.

public OutputStream
put(String
of the file to read
path
)

Implements org.eclipse.jgit.transport.FtpChannel.put.

Obtain an OutputStream to write to a remote file.

public String
pwd()

Implements org.eclipse.jgit.transport.FtpChannel.pwd.

Get current remote directory path

public void
rename(String
original name of the file
from
,
String
new name of the file
to
)

Implements org.eclipse.jgit.transport.FtpChannel.rename.

Renames a file on the remote file system.

public void
rm(String
to delete
path
)

Implements org.eclipse.jgit.transport.FtpChannel.rm.

Deletes a file on the remote file system.

public void
rmdir(String
to delete
path
)

Implements org.eclipse.jgit.transport.FtpChannel.rmdir.

Deletes a directory on the remote file system.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cwdback to summary
private String cwd

Current working directory.

ftpback to summary
private SftpClient ftp

Constructor Detail

SshdFtpChannelback to summary
private SshdFtpChannel()

Method Detail

absoluteback to summary
private String absolute(String path)
cdback to summary
public void cd(String path) throws IOException

Implements org.eclipse.jgit.transport.FtpChannel.cd.

Doc from org.eclipse.jgit.transport.FtpChannel.cd.

Changes the current remote directory.

Parameters
path:String

target directory

Annotations
@Override
Exceptions
IOException:
if the operation could not be performed remotely
connectback to summary
public void connect(int timeout, TimeUnit unit) throws IOException

Implements org.eclipse.jgit.transport.FtpChannel.connect.

Doc from org.eclipse.jgit.transport.FtpChannel.connect.

Connects the FtpChannel to the remote end.

Parameters
timeout:int

for establishing the FTP connection

unit:TimeUnit

of the timeout

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
disconnectback to summary
public void disconnect()

Implements org.eclipse.jgit.transport.FtpChannel.disconnect.

Doc from org.eclipse.jgit.transport.FtpChannel.disconnect.

Disconnects and FtpChannel.

Annotations
@Override
getback to summary
public InputStream get(String path) throws IOException

Implements org.eclipse.jgit.transport.FtpChannel.get.

Doc from org.eclipse.jgit.transport.FtpChannel.get.

Obtain an InputStream to read the contents of a remote file.

Parameters
path:String

of the file to read

Returns:InputStream

the stream to read from

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
isConnectedback to summary
public boolean isConnected()

Implements org.eclipse.jgit.transport.FtpChannel.isConnected.

Doc from org.eclipse.jgit.transport.FtpChannel.isConnected.

Whether the FtpChannel is connected

Returns:boolean

whether the FtpChannel is connected

Annotations
@Override
lsback to summary
public Collection<FtpChannel.DirEntry> ls(String path) throws IOException

Implements org.eclipse.jgit.transport.FtpChannel.ls.

Doc from org.eclipse.jgit.transport.FtpChannel.ls.

Lists contents of a remote directory

Parameters
path:String

of the directory to list

Returns:Collection<FtpChannel.DirEntry>

the directory entries

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
mapback to summary
private <T> T map(IOFunction<Void, T> op) throws IOException
mkdirback to summary
public void mkdir(String path) throws IOException

Implements org.eclipse.jgit.transport.FtpChannel.mkdir.

Doc from org.eclipse.jgit.transport.FtpChannel.mkdir.

Creates a directory on the remote file system.

Parameters
path:String

to create

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
putback to summary
public OutputStream put(String path) throws IOException

Implements org.eclipse.jgit.transport.FtpChannel.put.

Doc from org.eclipse.jgit.transport.FtpChannel.put.

Obtain an OutputStream to write to a remote file. If the file exists already, it will be overwritten.

Parameters
path:String

of the file to read

Returns:OutputStream

the stream to read from

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
pwdback to summary
public String pwd() throws IOException

Implements org.eclipse.jgit.transport.FtpChannel.pwd.

Doc from org.eclipse.jgit.transport.FtpChannel.pwd.

Get current remote directory path

Returns:String

the current remote directory path

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
renameback to summary
public void rename(String from, String to) throws IOException

Implements org.eclipse.jgit.transport.FtpChannel.rename.

Doc from org.eclipse.jgit.transport.FtpChannel.rename.

Renames a file on the remote file system. If to exists, it is replaced by from. (POSIX rename() semantics)

Parameters
from:String

original name of the file

to:String

new name of the file

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
rmback to summary
public void rm(String path) throws IOException

Implements org.eclipse.jgit.transport.FtpChannel.rm.

Doc from org.eclipse.jgit.transport.FtpChannel.rm.

Deletes a file on the remote file system.

Parameters
path:String

to delete

Annotations
@Override
Exceptions
IOException:
if the file does not exist or could otherwise not be deleted
rmdirback to summary
public void rmdir(String path) throws IOException

Implements org.eclipse.jgit.transport.FtpChannel.rmdir.

Doc from org.eclipse.jgit.transport.FtpChannel.rmdir.

Deletes a directory on the remote file system. The directory must be empty.

Parameters
path:String

to delete

Annotations
@Override
Exceptions
IOException:
if an IO error occurred