com.jcraft.jsch
Class ChannelSftp

java.lang.Object
  extended by com.jcraft.jsch.Channel
      extended by com.jcraft.jsch.ChannelSftp
All Implemented Interfaces:
java.lang.Runnable

public class ChannelSftp
extends Channel


Nested Class Summary
 class ChannelSftp.LsEntry
           
static interface ChannelSftp.LsEntrySelector
          This interface will be passed as an argument for ls method.
 
Field Summary
protected  boolean agent_forwarding
           
static int APPEND
           
protected  java.util.Hashtable env
           
static int OVERWRITE
           
protected  boolean pty
           
static int RESUME
           
static int SSH_FX_BAD_MESSAGE
           
static int SSH_FX_CONNECTION_LOST
           
static int SSH_FX_EOF
           
static int SSH_FX_FAILURE
           
static int SSH_FX_NO_CONNECTION
           
static int SSH_FX_NO_SUCH_FILE
           
static int SSH_FX_OK
           
static int SSH_FX_OP_UNSUPPORTED
           
static int SSH_FX_PERMISSION_DENIED
           
protected  int tcol
           
protected  byte[] terminal_mode
           
protected  int thp
           
protected  int trow
           
protected  java.lang.String ttype
           
protected  int twp
           
protected  boolean xforwading
           
 
Fields inherited from class com.jcraft.jsch.Channel
type
 
Constructor Summary
ChannelSftp()
           
 
Method Summary
 void _put(java.io.InputStream src, java.lang.String dst, SftpProgressMonitor monitor, int mode)
           
 void cd(java.lang.String path)
           
 void chgrp(int gid, java.lang.String path)
           
 void chmod(int permissions, java.lang.String path)
           
 void chown(int uid, java.lang.String path)
           
 void disconnect()
           
 void exit()
           
 java.io.InputStream get(java.lang.String src)
           
 java.io.InputStream get(java.lang.String src, int mode)
          Deprecated. This method will be deleted in the future.
 void get(java.lang.String src, java.io.OutputStream dst)
           
 void get(java.lang.String src, java.io.OutputStream dst, SftpProgressMonitor monitor)
           
 void get(java.lang.String src, java.io.OutputStream dst, SftpProgressMonitor monitor, int mode, long skip)
           
 java.io.InputStream get(java.lang.String src, SftpProgressMonitor monitor)
           
 java.io.InputStream get(java.lang.String src, SftpProgressMonitor monitor, int mode)
          Deprecated. This method will be deleted in the future.
 java.io.InputStream get(java.lang.String src, SftpProgressMonitor monitor, long skip)
           
 void get(java.lang.String src, java.lang.String dst)
           
 void get(java.lang.String src, java.lang.String dst, SftpProgressMonitor monitor)
           
 void get(java.lang.String src, java.lang.String dst, SftpProgressMonitor monitor, int mode)
           
 int getBulkRequests()
          This method will return the value how many requests may be sent at any one time.
 java.lang.String getExtension(java.lang.String key)
           
 java.lang.String getHome()
           
 int getServerVersion()
           
 void hardlink(java.lang.String oldpath, java.lang.String newpath)
           
 void lcd(java.lang.String path)
           
 java.lang.String lpwd()
           
 java.util.Vector ls(java.lang.String path)
           
 void ls(java.lang.String path, ChannelSftp.LsEntrySelector selector)
          List files specified by the remote path.
 SftpATTRS lstat(java.lang.String path)
           
 void mkdir(java.lang.String path)
           
 void put(java.io.InputStream src, java.lang.String dst)
           
 void put(java.io.InputStream src, java.lang.String dst, int mode)
           
 void put(java.io.InputStream src, java.lang.String dst, SftpProgressMonitor monitor)
           
 void put(java.io.InputStream src, java.lang.String dst, SftpProgressMonitor monitor, int mode)
          Sends data from the input stream src to dst file.
 java.io.OutputStream put(java.lang.String dst)
           
 java.io.OutputStream put(java.lang.String dst, int mode)
           
 java.io.OutputStream put(java.lang.String dst, SftpProgressMonitor monitor, int mode)
           
 java.io.OutputStream put(java.lang.String dst, SftpProgressMonitor monitor, int mode, long offset)
          Sends data from the output stream to dst file.
 void put(java.lang.String src, java.lang.String dst)
           
 void put(java.lang.String src, java.lang.String dst, int mode)
           
 void put(java.lang.String src, java.lang.String dst, SftpProgressMonitor monitor)
           
 void put(java.lang.String src, java.lang.String dst, SftpProgressMonitor monitor, int mode)
          Sends data from src file to dst file.
 java.lang.String pwd()
           
 void quit()
           
 java.lang.String readlink(java.lang.String path)
           
 java.lang.String realpath(java.lang.String path)
           
 void rename(java.lang.String oldpath, java.lang.String newpath)
           
 void rm(java.lang.String path)
           
 void rmdir(java.lang.String path)
           
 void run()
           
protected  void sendRequests()
           
 void setAgentForwarding(boolean enable)
          Enable the agent forwarding.
 void setBulkRequests(int bulk_requests)
          Specify how many requests may be sent at any one time.
 void setEnv(byte[] name, byte[] value)
          Set the environment variable.
 void setEnv(java.util.Hashtable env)
          Deprecated. Use setEnv(String, String) or setEnv(byte[], byte[]) instead.
 void setEnv(java.lang.String name, java.lang.String value)
          Set the environment variable.
 void setFilenameEncoding(java.lang.String encoding)
           
 void setMtime(java.lang.String path, int mtime)
           
 void setPty(boolean enable)
          Allocate a Pseudo-Terminal.
 void setPtySize(int col, int row, int wp, int hp)
          Change the window dimension interactively.
 void setPtyType(java.lang.String ttype)
          Set the terminal type.
 void setPtyType(java.lang.String ttype, int col, int row, int wp, int hp)
          Set the terminal type.
 void setStat(java.lang.String path, SftpATTRS attr)
           
 void setTerminalMode(byte[] terminal_mode)
          Set the terminal mode.
 void setXForwarding(boolean enable)
          Enable the X11 forwarding.
 void start()
           
 SftpATTRS stat(java.lang.String path)
           
 SftpStatVFS statVFS(java.lang.String path)
           
 void symlink(java.lang.String oldpath, java.lang.String newpath)
           
 java.lang.String version()
           
 
Methods inherited from class com.jcraft.jsch.Channel
connect, connect, genChannelOpenPacket, getExitStatus, getExtInputStream, getId, getInputStream, getOutputStream, getSession, isClosed, isConnected, isEOF, sendChannelOpen, sendOpenConfirmation, sendOpenFailure, sendSignal, setExtOutputStream, setExtOutputStream, setInputStream, setInputStream, setOutputStream, setOutputStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SSH_FX_OK

public static final int SSH_FX_OK
See Also:
Constant Field Values

SSH_FX_EOF

public static final int SSH_FX_EOF
See Also:
Constant Field Values

SSH_FX_NO_SUCH_FILE

public static final int SSH_FX_NO_SUCH_FILE
See Also:
Constant Field Values

SSH_FX_PERMISSION_DENIED

public static final int SSH_FX_PERMISSION_DENIED
See Also:
Constant Field Values

SSH_FX_FAILURE

public static final int SSH_FX_FAILURE
See Also:
Constant Field Values

SSH_FX_BAD_MESSAGE

public static final int SSH_FX_BAD_MESSAGE
See Also:
Constant Field Values

SSH_FX_NO_CONNECTION

public static final int SSH_FX_NO_CONNECTION
See Also:
Constant Field Values

SSH_FX_CONNECTION_LOST

public static final int SSH_FX_CONNECTION_LOST
See Also:
Constant Field Values

SSH_FX_OP_UNSUPPORTED

public static final int SSH_FX_OP_UNSUPPORTED
See Also:
Constant Field Values

OVERWRITE

public static final int OVERWRITE
See Also:
Constant Field Values

RESUME

public static final int RESUME
See Also:
Constant Field Values

APPEND

public static final int APPEND
See Also:
Constant Field Values

agent_forwarding

protected boolean agent_forwarding

xforwading

protected boolean xforwading

env

protected java.util.Hashtable env

pty

protected boolean pty

ttype

protected java.lang.String ttype

tcol

protected int tcol

trow

protected int trow

twp

protected int twp

thp

protected int thp

terminal_mode

protected byte[] terminal_mode
Constructor Detail

ChannelSftp

public ChannelSftp()
Method Detail

setBulkRequests

public void setBulkRequests(int bulk_requests)
                     throws JSchException
Specify how many requests may be sent at any one time. Increasing this value may slightly improve file transfer speed but will increase memory usage. The default is 16 requests.

Parameters:
bulk_requests - how many requests may be outstanding at any one time.
Throws:
JSchException

getBulkRequests

public int getBulkRequests()
This method will return the value how many requests may be sent at any one time.

Returns:
how many requests may be sent at any one time.

start

public void start()
           throws JSchException
Overrides:
start in class Channel
Throws:
JSchException

quit

public void quit()

exit

public void exit()

lcd

public void lcd(java.lang.String path)
         throws SftpException
Throws:
SftpException

cd

public void cd(java.lang.String path)
        throws SftpException
Throws:
SftpException

put

public void put(java.lang.String src,
                java.lang.String dst)
         throws SftpException
Throws:
SftpException

put

public void put(java.lang.String src,
                java.lang.String dst,
                int mode)
         throws SftpException
Throws:
SftpException

put

public void put(java.lang.String src,
                java.lang.String dst,
                SftpProgressMonitor monitor)
         throws SftpException
Throws:
SftpException

put

public void put(java.lang.String src,
                java.lang.String dst,
                SftpProgressMonitor monitor,
                int mode)
         throws SftpException
Sends data from src file to dst file. The mode should be OVERWRITE, RESUME or APPEND.

Parameters:
src - source file
dst - destination file
monitor - progress monitor
mode - how data should be added to dst
Throws:
SftpException

put

public void put(java.io.InputStream src,
                java.lang.String dst)
         throws SftpException
Throws:
SftpException

put

public void put(java.io.InputStream src,
                java.lang.String dst,
                int mode)
         throws SftpException
Throws:
SftpException

put

public void put(java.io.InputStream src,
                java.lang.String dst,
                SftpProgressMonitor monitor)
         throws SftpException
Throws:
SftpException

put

public void put(java.io.InputStream src,
                java.lang.String dst,
                SftpProgressMonitor monitor,
                int mode)
         throws SftpException
Sends data from the input stream src to dst file. The mode should be OVERWRITE, RESUME or APPEND.

Parameters:
src - input stream
dst - destination file
monitor - progress monitor
mode - how data should be added to dst
Throws:
SftpException

_put

public void _put(java.io.InputStream src,
                 java.lang.String dst,
                 SftpProgressMonitor monitor,
                 int mode)
          throws SftpException
Throws:
SftpException

put

public java.io.OutputStream put(java.lang.String dst)
                         throws SftpException
Throws:
SftpException

put

public java.io.OutputStream put(java.lang.String dst,
                                int mode)
                         throws SftpException
Throws:
SftpException

put

public java.io.OutputStream put(java.lang.String dst,
                                SftpProgressMonitor monitor,
                                int mode)
                         throws SftpException
Throws:
SftpException

put

public java.io.OutputStream put(java.lang.String dst,
                                SftpProgressMonitor monitor,
                                int mode,
                                long offset)
                         throws SftpException
Sends data from the output stream to dst file. The mode should be OVERWRITE, RESUME or APPEND.

Parameters:
dst - destination file
monitor - progress monitor
mode - how data should be added to dst
offset - data will be added at offset
Returns:
output stream, which accepts data to be transferred.
Throws:
SftpException

get

public void get(java.lang.String src,
                java.lang.String dst)
         throws SftpException
Throws:
SftpException

get

public void get(java.lang.String src,
                java.lang.String dst,
                SftpProgressMonitor monitor)
         throws SftpException
Throws:
SftpException

get

public void get(java.lang.String src,
                java.lang.String dst,
                SftpProgressMonitor monitor,
                int mode)
         throws SftpException
Throws:
SftpException

get

public void get(java.lang.String src,
                java.io.OutputStream dst)
         throws SftpException
Throws:
SftpException

get

public void get(java.lang.String src,
                java.io.OutputStream dst,
                SftpProgressMonitor monitor)
         throws SftpException
Throws:
SftpException

get

public void get(java.lang.String src,
                java.io.OutputStream dst,
                SftpProgressMonitor monitor,
                int mode,
                long skip)
         throws SftpException
Throws:
SftpException

get

public java.io.InputStream get(java.lang.String src)
                        throws SftpException
Throws:
SftpException

get

public java.io.InputStream get(java.lang.String src,
                               SftpProgressMonitor monitor)
                        throws SftpException
Throws:
SftpException

get

public java.io.InputStream get(java.lang.String src,
                               int mode)
                        throws SftpException
Deprecated. This method will be deleted in the future.

Throws:
SftpException

get

public java.io.InputStream get(java.lang.String src,
                               SftpProgressMonitor monitor,
                               int mode)
                        throws SftpException
Deprecated. This method will be deleted in the future.

Throws:
SftpException

get

public java.io.InputStream get(java.lang.String src,
                               SftpProgressMonitor monitor,
                               long skip)
                        throws SftpException
Throws:
SftpException

ls

public java.util.Vector ls(java.lang.String path)
                    throws SftpException
Throws:
SftpException

ls

public void ls(java.lang.String path,
               ChannelSftp.LsEntrySelector selector)
        throws SftpException
List files specified by the remote path. Each files and directories will be passed to LsEntrySelector#select(LsEntry) method, and if that method returns LsEntrySelector#BREAK, the operation will be canceled immediately.

Throws:
SftpException
Since:
0.1.47
See Also:
ChannelSftp.LsEntrySelector

readlink

public java.lang.String readlink(java.lang.String path)
                          throws SftpException
Throws:
SftpException

symlink

public void symlink(java.lang.String oldpath,
                    java.lang.String newpath)
             throws SftpException
Throws:
SftpException

hardlink

public void hardlink(java.lang.String oldpath,
                     java.lang.String newpath)
              throws SftpException
Throws:
SftpException

rename

public void rename(java.lang.String oldpath,
                   java.lang.String newpath)
            throws SftpException
Throws:
SftpException

rm

public void rm(java.lang.String path)
        throws SftpException
Throws:
SftpException

chgrp

public void chgrp(int gid,
                  java.lang.String path)
           throws SftpException
Throws:
SftpException

chown

public void chown(int uid,
                  java.lang.String path)
           throws SftpException
Throws:
SftpException

chmod

public void chmod(int permissions,
                  java.lang.String path)
           throws SftpException
Throws:
SftpException

setMtime

public void setMtime(java.lang.String path,
                     int mtime)
              throws SftpException
Throws:
SftpException

rmdir

public void rmdir(java.lang.String path)
           throws SftpException
Throws:
SftpException

mkdir

public void mkdir(java.lang.String path)
           throws SftpException
Throws:
SftpException

stat

public SftpATTRS stat(java.lang.String path)
               throws SftpException
Throws:
SftpException

statVFS

public SftpStatVFS statVFS(java.lang.String path)
                    throws SftpException
Throws:
SftpException

lstat

public SftpATTRS lstat(java.lang.String path)
                throws SftpException
Throws:
SftpException

setStat

public void setStat(java.lang.String path,
                    SftpATTRS attr)
             throws SftpException
Throws:
SftpException

pwd

public java.lang.String pwd()
                     throws SftpException
Throws:
SftpException

lpwd

public java.lang.String lpwd()

version

public java.lang.String version()

getHome

public java.lang.String getHome()
                         throws SftpException
Throws:
SftpException

disconnect

public void disconnect()
Overrides:
disconnect in class Channel

getServerVersion

public int getServerVersion()
                     throws SftpException
Throws:
SftpException

setFilenameEncoding

public void setFilenameEncoding(java.lang.String encoding)
                         throws SftpException
Throws:
SftpException

getExtension

public java.lang.String getExtension(java.lang.String key)

realpath

public java.lang.String realpath(java.lang.String path)
                          throws SftpException
Throws:
SftpException

setAgentForwarding

public void setAgentForwarding(boolean enable)
Enable the agent forwarding.

Parameters:
enable -

setXForwarding

public void setXForwarding(boolean enable)
Enable the X11 forwarding. Refer to RFC4254 6.3.1. Requesting X11 Forwarding.

Overrides:
setXForwarding in class Channel
Parameters:
enable -

setEnv

public void setEnv(java.util.Hashtable env)
Deprecated. Use setEnv(String, String) or setEnv(byte[], byte[]) instead.

See Also:
setEnv(String, String), setEnv(byte[], byte[])

setEnv

public void setEnv(java.lang.String name,
                   java.lang.String value)
Set the environment variable. If name and value are needed to be passed to the remote in your favorite encoding, use setEnv(byte[], byte[]). Refer to RFC4254 6.4 Environment Variable Passing.

Parameters:
name - A name for environment variable.
value - A value for environment variable.

setEnv

public void setEnv(byte[] name,
                   byte[] value)
Set the environment variable. Refer to RFC4254 6.4 Environment Variable Passing.

Parameters:
name - A name of environment variable.
value - A value of environment variable.
See Also:
setEnv(String, String)

setPty

public void setPty(boolean enable)
Allocate a Pseudo-Terminal. Refer to RFC4254 6.2. Requesting a Pseudo-Terminal.

Parameters:
enable -

setTerminalMode

public void setTerminalMode(byte[] terminal_mode)
Set the terminal mode.

Parameters:
terminal_mode -

setPtySize

public void setPtySize(int col,
                       int row,
                       int wp,
                       int hp)
Change the window dimension interactively. Refer to RFC4254 6.7. Window Dimension Change Message.

Parameters:
col - terminal width, columns
row - terminal height, rows
wp - terminal width, pixels
hp - terminal height, pixels

setPtyType

public void setPtyType(java.lang.String ttype)
Set the terminal type. This method is not effective after Channel#connect().

Parameters:
ttype - terminal type(for example, "vt100")
See Also:
setPtyType(String, int, int, int, int)

setPtyType

public void setPtyType(java.lang.String ttype,
                       int col,
                       int row,
                       int wp,
                       int hp)
Set the terminal type. This method is not effective after Channel#connect().

Parameters:
ttype - terminal type(for example, "vt100")
col - terminal width, columns
row - terminal height, rows
wp - terminal width, pixels
hp - terminal height, pixels

sendRequests

protected void sendRequests()
                     throws java.lang.Exception
Throws:
java.lang.Exception

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class Channel