com.sshtools.j2ssh
Class ScpClient.ScpChannel

java.lang.Object
  extended by com.sshtools.j2ssh.connection.Channel
      extended by com.sshtools.j2ssh.connection.IOChannel
          extended by com.sshtools.j2ssh.session.SessionChannelClient
              extended by com.sshtools.j2ssh.ScpClient.ScpChannel
Enclosing class:
ScpClient

 class ScpClient.ScpChannel
extends SessionChannelClient

Implements an SCP channel by extending the SessionChannelClient.

Since:
0.2.0

Field Summary
(package private)  byte[] buffer
           
(package private)  java.lang.String cmd
           
 
Fields inherited from class com.sshtools.j2ssh.connection.IOChannel
boundInputStream, boundOutputStream, in, ios, out
 
Fields inherited from class com.sshtools.j2ssh.connection.Channel
connection, localChannelId, localPacketSize, localWindow, remoteChannelId, remotePacketSize, remoteWindow, state
 
Constructor Summary
ScpClient.ScpChannel(java.lang.String cmd)
           Contruct the channel with the specified scp command.
 
Method Summary
protected  void onChannelOpen()
           This implementation executes the scp command when the channel is opened.
private  void parseCommand(java.lang.String cmd, java.lang.String[] cmdParts)
           
private  void readCompleteFile(java.io.FileOutputStream file, long size)
           
private  void readFromRemote(java.io.File file)
           
private  java.io.InputStream readStreamFromRemote()
           
private  java.lang.String readString()
           
private  void waitForResponse()
           
private  void writeCompleteFile(java.io.InputStream file, long size)
           
private  boolean writeDirToRemote(java.io.File dir, boolean recursive)
           Writes a directory to the remote server.
private  void writeError(java.lang.String reason)
           
private  void writeFileToRemote(java.io.File file, boolean recursive)
           Write a file to the remote server.
private  void writeOk()
           
private  void writeStreamToRemote(java.io.InputStream in, long length, java.lang.String localName)
           Write a stream as a file to the remote server.
 
Methods inherited from class com.sshtools.j2ssh.session.SessionChannelClient
changeTerminalDimensions, executeCommand, getChannelConfirmationData, getChannelOpenData, getChannelType, getExitCode, getMaximumPacketSize, getMaximumWindowSpace, getMinimumWindowSpace, getSessionType, getStderrInputStream, getSubsystem, isLocalFlowControlEnabled, onChannelClose, onChannelExtData, onChannelRequest, requestAgentForwarding, requestPseudoTerminal, requestPseudoTerminal, requestX11Forwarding, setEnvironmentVariable, setSessionType, setSignalListener, startShell, startSubsystem, startSubsystem
 
Methods inherited from class com.sshtools.j2ssh.connection.IOChannel
bindInputStream, bindOutputStream, getInputStream, getOutputStream, init, onChannelData, onChannelEOF, open, setLocalEOF
 
Methods inherited from class com.sshtools.j2ssh.connection.Channel
addEventListener, close, finalizeClose, getLocalChannelId, getLocalPacketSize, getLocalWindow, getName, getRemoteChannelId, getRemotePacketSize, getRemoteWindow, getState, init, isClosed, isLocalEOF, isOpen, isRemoteEOF, processChannelData, processChannelData, remoteClose, sendChannelData, sendChannelExtData, setName, setRemoteEOF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

byte[] buffer

cmd

java.lang.String cmd
Constructor Detail

ScpClient.ScpChannel

ScpClient.ScpChannel(java.lang.String cmd)

Contruct the channel with the specified scp command.

Parameters:
cmd - The scp command
Since:
0.2.0
Method Detail

onChannelOpen

protected void onChannelOpen()
                      throws java.io.IOException

This implementation executes the scp command when the channel is opened.

Overrides:
onChannelOpen in class SessionChannelClient
Throws:
java.io.IOException
Since:
0.2.0

writeDirToRemote

private boolean writeDirToRemote(java.io.File dir,
                                 boolean recursive)
                          throws java.io.IOException

Writes a directory to the remote server.

Parameters:
dir - The source directory
recursive - Add the contents of the directory recursivley
Returns:
true if the file was written, otherwise false
Throws:
java.io.IOException - if an IO error occurs
Since:
0.2.0

writeStreamToRemote

private void writeStreamToRemote(java.io.InputStream in,
                                 long length,
                                 java.lang.String localName)
                          throws java.io.IOException

Write a stream as a file to the remote server. You must supply the correct number of bytes that will be written.

Parameters:
in - stream
length - number of bytes to write
localName - local file name
Throws:
java.io.IOException - if an IO error occurs
Since:
0.2.0

writeFileToRemote

private void writeFileToRemote(java.io.File file,
                               boolean recursive)
                        throws java.io.IOException

Write a file to the remote server.

Parameters:
file - The source file
recursive - Add the contents of the directory recursivley
Throws:
java.io.IOException - if an IO error occurs
Since:
0.2.0

readFromRemote

private void readFromRemote(java.io.File file)
                     throws java.io.IOException
Throws:
java.io.IOException

readStreamFromRemote

private java.io.InputStream readStreamFromRemote()
                                          throws java.io.IOException
Throws:
java.io.IOException

parseCommand

private void parseCommand(java.lang.String cmd,
                          java.lang.String[] cmdParts)
                   throws java.io.IOException
Throws:
java.io.IOException

readString

private java.lang.String readString()
                             throws java.io.IOException
Throws:
java.io.IOException

waitForResponse

private void waitForResponse()
                      throws java.io.IOException
Throws:
java.io.IOException

writeOk

private void writeOk()
              throws java.io.IOException
Throws:
java.io.IOException

writeError

private void writeError(java.lang.String reason)
                 throws java.io.IOException
Throws:
java.io.IOException

writeCompleteFile

private void writeCompleteFile(java.io.InputStream file,
                               long size)
                        throws java.io.IOException
Throws:
java.io.IOException

readCompleteFile

private void readCompleteFile(java.io.FileOutputStream file,
                              long size)
                       throws java.io.IOException
Throws:
java.io.IOException