public class SftpSubsystem extends Object implements Command, SessionAware, FileSystemAware, SftpSession, ChannelDataReceiver, ChannelSessionAware
Modifier and Type | Class and Description |
---|---|
static class |
SftpSubsystem.Factory |
Modifier and Type | Field and Description |
---|---|
static String |
ALL_SFTP_IMPL |
static int |
HIGHER_SFTP_IMPL |
protected static org.slf4j.Logger |
LOG |
static int |
LOWER_SFTP_IMPL |
static String |
MAX_OPEN_HANDLES_PER_SESSION
Properties key for the maximum of available open handles per session.
|
static int |
MAX_PACKET_LENGTH |
Constructor and Description |
---|
SftpSubsystem() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Called to indicate EOF.
|
Handle |
createDirectoryHandle(SshFile file) |
Handle |
createFileHandle(SshFile file,
int flags) |
int |
data(ChannelSession channel,
byte[] buf,
int start,
int len)
Called when the server receives additional bytes from the client.
|
void |
destroy()
Destroy the shell.
|
protected Reply |
doProcess(Request request) |
Handle |
getHandle(String id) |
Session |
getSession() |
int |
getVersion() |
void |
process(Buffer buffer) |
protected boolean |
receive(Buffer incoming) |
protected void |
send(Buffer buffer) |
protected SshFxpNameReply |
sendName(int id,
Iterator<SshFile> files) |
void |
setChannelSession(ChannelSession channel)
Receives the channel in which the command is being executed.
|
void |
setErrorStream(OutputStream err)
Set the error stream that can be used by the shell to write its errors.
|
void |
setExitCallback(ExitCallback callback)
Set the callback that the shell has to call when it is closed.
|
void |
setFileSystemView(FileSystemView view)
Set the file system in which this shell will be executed.
|
void |
setInputStream(InputStream in)
Set the input stream that can be used by the shell to read input.
|
void |
setOutputStream(OutputStream out)
Set the output stream that can be used by the shell to write its output.
|
void |
setSession(ServerSession session)
Set the server session in which this shell will be executed.
|
void |
setSftpLet(Sftplet sftpLet) |
void |
start(Environment env)
Starts the shell.
|
protected static final org.slf4j.Logger LOG
public static final int LOWER_SFTP_IMPL
public static final int HIGHER_SFTP_IMPL
public static final String ALL_SFTP_IMPL
public static final int MAX_PACKET_LENGTH
public static final String MAX_OPEN_HANDLES_PER_SESSION
public void setSftpLet(Sftplet sftpLet)
public int getVersion()
getVersion
in interface SftpSession
public Session getSession()
getSession
in interface SftpSession
public Handle getHandle(String id)
getHandle
in interface SftpSession
public Handle createFileHandle(SshFile file, int flags)
createFileHandle
in interface SftpSession
public Handle createDirectoryHandle(SshFile file)
createDirectoryHandle
in interface SftpSession
public void setChannelSession(ChannelSession channel)
ChannelSessionAware
setChannelSession
in interface ChannelSessionAware
channel
- never nullpublic void setSession(ServerSession session)
SessionAware
setSession
in interface SessionAware
public void setFileSystemView(FileSystemView view)
FileSystemAware
setFileSystemView
in interface FileSystemAware
public void setExitCallback(ExitCallback callback)
Command
setExitCallback
in interface Command
public void setInputStream(InputStream in)
Command
setInputStream
in interface Command
public void setOutputStream(OutputStream out)
Command
setOutputStream
in interface Command
public void setErrorStream(OutputStream err)
Command
setErrorStream
in interface Command
public void start(Environment env) throws IOException
Command
Thread(this).start();
start
in interface Command
IOException
public int data(ChannelSession channel, byte[] buf, int start, int len) throws IOException
ChannelDataReceiver
SSH channels use the windowing mechanism to perform flow control, much like TCP does. The server gives the client the initial window size, which represents the number of bytes the client can send to the server. As the server receives data, it can send a message to the client to allow it to send more data.
The return value from this method is used to control this behaviour. Intuitively speaking, the callee returns the number of bytes consumed by this method, by the time this method returns. Picture a one-way long bridge (for example Golden Gate Bridge) with toll plazas on both sides. The window size is the maximum number of cars allowed on the bridge. Here we are on the receiving end, so our job here is to count the number of cars as it leaves the bridge, and if enough of them left, we'll signal the sending end that they can let in more cars. The return value of this method counts the number of cars that are leaving in this batch.
In simple cases, where the callee has consumed the bytes before it returns, the return value must be the same value as the 'len' parameter given.
On the other hand, if the callee is queueing up the received bytes somewhere
to be consumed later (for example by another thread), then this method should
return 0, for the bytes aren't really consumed yet. And when at some later point
the bytes are actually used, then you'll invoke channel.getLocalWindow().consumeAndCheck(len)
to let the channel know that bytes are consumed.
This behaviour will result in a better flow control, as the server will not allow the SSH client to overflow its buffer. If instead you always return the value passed in the 'len' parameter, the place where you are queueing up bytes may overflow.
In either case, the callee must account for every bytes it receives in this method.
Returning 0 and failing to call back channel.getLocalWindow().consumeAndCheck(len)
later
will dry up the window size, and eventually the client will stop sending you any data.
In the SSH protocol, this method invocation is triggered by a SSH_MSG_CHANNEL_DATA message.
data
in interface ChannelDataReceiver
channel
- The caller to which this ChannelDataReceiver
is assigned. Never null.buf
- Holds the bytes received. This buffer belongs to the caller, and it might get reused
by the caller as soon as this method returns.start
- buf[start] is the first byte that received from the client.len
- the length of the bytes received. Can be zero.IOException
protected boolean receive(Buffer incoming) throws IOException
IOException
public void close() throws IOException
ChannelDataReceiver
close
in interface Closeable
close
in interface AutoCloseable
close
in interface ChannelDataReceiver
IOException
public void process(Buffer buffer) throws IOException
IOException
protected Reply doProcess(Request request) throws IOException
IOException
protected SshFxpNameReply sendName(int id, Iterator<SshFile> files) throws IOException
IOException
protected void send(Buffer buffer) throws IOException
IOException
Copyright © 2008–2016 The Apache Software Foundation. All rights reserved.