com.sshtools.sftp
Interface SftpClient

All Known Implementing Classes:
AbstractSftpClient, ScpFallbackImpl, SftpClientImpl

public interface SftpClient


Field Summary
static int EOL_CR
           Specifies that the remote server is using \r as its newline convention when used with setRemoteEOL(int)
static int EOL_CRLF
           Specifies that the remote server is using \r\n as its newline convention when used with setRemoteEOL(int)
static int EOL_LF
           Specifies that the remote server is using \n as its newline convention when used with setRemoteEOL(int)
static int GlobSyntax
           
static int MODE_BINARY
          Instructs the client to use a binary transfer mode when used with setTransferMode(int)
static int MODE_TEXT
          Instructs the client to use a text transfer mode when used with setTransferMode(int).
static int NoSyntax
          constants for setting the regular expression syntax.
static int Perl5Syntax
           
 
Method Summary
 void addCustomRoot(String rootPath)
          Add a custom file system root path such as "flash:"
 void cd(String dir)
           Changes the working directory on the remote server, or the home directory if null or any empty string is provided as the directory path
 void cdup()
          Change the working directory to the parent directory
 void chgrp(String gid, String path)
           Sets the group ID for the file or directory.
 void chmod(int permissions, String path)
           Changes the access permissions or modes of the specified file or directory.
 void chown(String uid, String path)
           Sets the user ID to owner for the file or directory.
 DirectoryOperation copyLocalDirectory(String localdir, String remotedir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress)
          Copy the contents of a local directory into a remote remote directory.
 DirectoryOperation copyRemoteDirectory(String remotedir, String localdir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress)
          Copy the contents of a remote directory to a local directory
 void exit()
           Close the SFTP client.
 SftpFileAttributes get(String path)
           Download the remote file to the local computer
 SftpFileAttributes get(String path, boolean resume)
           Download the remote file to the local computer
 SftpFileAttributes get(String path, FileTransferProgress progress)
           Download the remote file to the local computer.
 SftpFileAttributes get(String path, FileTransferProgress progress, boolean resume)
           Download the remote file to the local computer.
 SftpFileAttributes get(String remote, OutputStream local)
          Download the remote file into an OutputStream.
 SftpFileAttributes get(String remote, OutputStream local, FileTransferProgress progress)
           Download the remote file writing it to the specified OutputStream.
 SftpFileAttributes get(String remote, OutputStream local, FileTransferProgress progress, long position)
           Download the remote file writing it to the specified OutputStream.
 SftpFileAttributes get(String remote, OutputStream local, long position)
          Download the remote file into an OutputStream.
 SftpFileAttributes get(String remote, String local)
          Download the remote file into the local file.
 SftpFileAttributes get(String remote, String local, boolean resume)
          Download the remote file into the local file.
 SftpFileAttributes get(String remote, String local, FileTransferProgress progress)
           Download the remote file to the local computer.
 SftpFileAttributes get(String remote, String local, FileTransferProgress progress, boolean resume)
           Download the remote file to the local computer.
 String getAbsolutePath(String path)
          Get the absolute path for a file.
 String getCharsetEncoding()
           
 String getDefaultDirectory()
           Get the default directory (or HOME directory)
 SftpFile getFile(String path)
           
 SftpFile[] getFiles(String remote)
           Download the remote files to the local computer
 SftpFile[] getFiles(String remote, boolean resume)
           Download the remote files to the local computer
 SftpFile[] getFiles(String remote, FileTransferProgress progress)
           Download the remote files to the local computer.
 SftpFile[] getFiles(String remote, FileTransferProgress progress, boolean resume)
           Download the remote files to the local computer.
 SftpFile[] getFiles(String remote, OutputStream local)
          Download the remote files into an OutputStream.
 SftpFile[] getFiles(String remote, OutputStream local, FileTransferProgress progress)
           Download the remote files writing it to the specified OutputStream.
 SftpFile[] getFiles(String remote, OutputStream local, FileTransferProgress progress, long position)
          make local copies of some of the variables, then call getfilematches, which calls get on each file that matches the regexp remote.
 SftpFile[] getFiles(String remote, OutputStream local, long position)
          Download the remote files into an OutputStream.
 SftpFile[] getFiles(String remote, String local)
          Download the remote files into the local file.
 SftpFile[] getFiles(String remote, String local, boolean resume)
          Download the remote files into the local file.
 SftpFile[] getFiles(String remote, String local, FileTransferProgress progress)
           Download the remote file to the local computer.
 SftpFile[] getFiles(String remote, String local, FileTransferProgress progress, boolean resume)
          make local copies of some of the variables, then call getfilematches, which calls get on each file that matches the regexp remote.
 InputStream getInputStream(String remotefile)
          Create an InputStream for reading a remote file.
 InputStream getInputStream(String remotefile, long position)
          Create an InputStream for reading a remote file.
 OutputStream getOutputStream(String remotefile)
          Create an OutputStream for writing to a remote file.
 int getTransferMode()
           
 int getVersion()
           
 boolean isClosed()
           Returns the state of the SFTP client.
 boolean isDirectoryOrLinkedDirectory(SftpFile file)
          Determine whether the file object is pointing to a symbolic link that is pointing to a directory.
 void lcd(String path)
           Changes the local working directory.
 String lpwd()
           Returns the absolute path to the local working directory.
 SftpFile[] ls()
           List the contents of the current remote working directory.
 SftpFile[] ls(String path)
           List the contents remote directory.
 void mkdir(String dir)
           Creates a new directory on the remote server.
 void mkdirs(String dir)
           Create a directory or set of directories.
 void put(InputStream in, String remote)
          Upload the contents of an InputStream to the remote computer.
 void put(InputStream in, String remote, FileTransferProgress progress)
           Upload a file to the remote computer reading from the specified InputStream .
 void put(InputStream in, String remote, FileTransferProgress progress, long position)
           
 void put(InputStream in, String remote, long position)
          Upload the contents of an InputStream to the remote computer.
 void put(String local)
          Upload a file to the remote computer
 void put(String local, boolean resume)
          Upload a file to the remote computer
 void put(String local, FileTransferProgress progress)
           Upload a file to the remote computer.
 void put(String local, FileTransferProgress progress, boolean resume)
           Upload a file to the remote computer.
 void put(String local, String remote)
          Upload a file to the remote computer
 void put(String local, String remote, boolean resume)
          Upload a file to the remote computer
 void put(String local, String remote, FileTransferProgress progress)
           Upload a file to the remote computer.
 void put(String local, String remote, FileTransferProgress progress, boolean resume)
           Upload a file to the remote computer.
 void putFiles(InputStream in, String remote)
           Upload the contents of an InputStream to the remote computer.
 void putFiles(InputStream in, String remote, FileTransferProgress progress)
           Upload files to the remote computer reading from the specified InputStream .
 void putFiles(InputStream in, String remote, FileTransferProgress progress, long position)
           
 void putFiles(InputStream in, String remote, long position)
          Upload the contents of an InputStream to the remote computer.
 void putFiles(String local)
           Upload the contents of an InputStream to the remote computer.
 void putFiles(String local, boolean resume)
          Upload files to the remote computer
 void putFiles(String local, FileTransferProgress progress)
           Upload files to the remote computer
 void putFiles(String local, FileTransferProgress progress, boolean resume)
           Upload files to the remote computer
 void putFiles(String local, String remote)
          Upload files to the remote computer
 void putFiles(String local, String remote, boolean resume)
          Upload files to the remote computer
 void putFiles(String local, String remote, FileTransferProgress progress)
           Upload files to the remote computer.
 void putFiles(String local, String remote, FileTransferProgress progress, boolean resume)
          make local copies of some of the variables, then call putfilematches, which calls "put" on each file that matches the regexp local.
 String pwd()
           Returns the absolute path name of the current remote working directory.
 void quit()
           Close the SFTP client.
 void removeCustomRoot(String rootPath)
          Remove a custom file system root path such as "flash:"
 void rename(String oldpath, String newpath)
           Rename a file on the remote computer.
 void rm(String path)
           Remove a file or directory from the remote computer.
 void rm(String path, boolean force, boolean recurse)
          Remove a file or directory on the remote computer with options to force deletion of existing files and recursion.
 void setAttributes(String path, SftpFileAttributes attrs)
           Updates a file's attributes.
 void setRegularExpressionSyntax(int syntax)
          sets the type of regular expression matching to perform on gets and puts
 void setRemoteEOL(int eolMode)
           When connected to servers running SFTP version 3 (or less) the remote EOL type needs to be explicitly set because there is no reliable way for the client to determine the type of EOL for text files.
 void setTransferMode(int transferMode)
           Sets the transfer mode for current operations.
 SftpFileAttributes stat(String path)
           Returns the attributes of the file from the remote computer.
 void symlink(String path, String link)
           Create a symbolic link on the remote computer.
 int umask(int umask)
          Sets the umask used by this client.
 void umask(String umask)
          Sets the umask for this client.
 

Field Detail

MODE_BINARY

static final int MODE_BINARY
Instructs the client to use a binary transfer mode when used with setTransferMode(int)

See Also:
Constant Field Values

MODE_TEXT

static final int MODE_TEXT
Instructs the client to use a text transfer mode when used with setTransferMode(int).

See Also:
Constant Field Values

EOL_CRLF

static final int EOL_CRLF

Specifies that the remote server is using \r\n as its newline convention when used with setRemoteEOL(int)

See Also:
Constant Field Values

EOL_LF

static final int EOL_LF

Specifies that the remote server is using \n as its newline convention when used with setRemoteEOL(int)

See Also:
Constant Field Values

EOL_CR

static final int EOL_CR

Specifies that the remote server is using \r as its newline convention when used with setRemoteEOL(int)

See Also:
Constant Field Values

NoSyntax

static final int NoSyntax
constants for setting the regular expression syntax.

See Also:
Constant Field Values

GlobSyntax

static final int GlobSyntax
See Also:
Constant Field Values

Perl5Syntax

static final int Perl5Syntax
See Also:
Constant Field Values
Method Detail

setTransferMode

void setTransferMode(int transferMode)

Sets the transfer mode for current operations. The valid modes are:

MODE_BINARY - Files are transferred in binary mode and no processing of text files is performed (default mode).

MODE_TEXT - For servers supporting version 4+ of the SFTP protocol files are transferred in text mode. For earlier protocol versions the files are transfered in binary mode but the client performs processing of text; if files are written to the remote server the client ensures that the line endings conform to the remote EOL mode set using setRemoteEOL(int). For files retrieved from the server the EOL policy is based upon System policy as defined by the "line.seperator" system property.

Parameters:
transferMode - int

setRemoteEOL

void setRemoteEOL(int eolMode)

When connected to servers running SFTP version 3 (or less) the remote EOL type needs to be explicitly set because there is no reliable way for the client to determine the type of EOL for text files. In versions 4+ a mechanism is provided and this setting is overridden.

Valid values for this method are EOL_CRLF (default), EOL_CR, and EOL_LF.

Parameters:
eolMode - int

getTransferMode

int getTransferMode()
Returns:
int

umask

int umask(int umask)
Sets the umask used by this client.
 To give yourself full permissions for both files and directories and
 prevent the group and other users from having access:
 
   umask(077);
 
 This subtracts 077 from the system defaults for files and directories
 666 and 777. Giving a default access permissions for your files of
 600 (rw-------) and for directories of 700 (rwx------).
 
 To give all access permissions to the group and allow other users read
 and execute permission:
 
   umask(002);
 
 This subtracts 002 from the system defaults to give a default access permission
 for your files of 664 (rw-rw-r--) and for your directories of 775 (rwxrwxr-x).
 
 To give the group and other users all access except write access:
 
   umask(022);
 
 This subtracts 022 from the system defaults to give a default access permission
 for your files of 644 (rw-r--r--) and for your directories of 755 (rwxr-xr-x).
 

Parameters:
umask -
Returns:
the previous umask value

cd

void cd(String dir)
        throws SftpStatusException,
               SshException

Changes the working directory on the remote server, or the home directory if null or any empty string is provided as the directory path

Parameters:
dir - the new working directory
Throws:
IOException - if an IO error occurs or the file does not exist
SftpStatusException
SshException

getDefaultDirectory

String getDefaultDirectory()
                           throws SftpStatusException,
                                  SshException

Get the default directory (or HOME directory)

Returns:
String
Throws:
SftpStatusException
SshException

cdup

void cdup()
          throws SftpStatusException,
                 SshException
Change the working directory to the parent directory

Throws:
SftpStatusException
SshException

addCustomRoot

void addCustomRoot(String rootPath)
Add a custom file system root path such as "flash:"

Parameters:
rootPath -

removeCustomRoot

void removeCustomRoot(String rootPath)
Remove a custom file system root path such as "flash:"

Parameters:
rootPath -

mkdir

void mkdir(String dir)
           throws SftpStatusException,
                  SshException

Creates a new directory on the remote server. This method will throw an exception if the directory already exists. To create directories and disregard any errors use the mkdirs method.

Parameters:
dir - the name of the new directory
Throws:
SftpStatusException
SshException

mkdirs

void mkdirs(String dir)
            throws SftpStatusException,
                   SshException

Create a directory or set of directories. This method will not fail even if the directories exist. It is advisable to test whether the directory exists before attempting an operation by using stat to return the directories attributes.

Parameters:
dir - the path of directories to create.
Throws:
SftpStatusException
SshException

isDirectoryOrLinkedDirectory

boolean isDirectoryOrLinkedDirectory(SftpFile file)
                                     throws SftpStatusException,
                                            SshException
Determine whether the file object is pointing to a symbolic link that is pointing to a directory.

Returns:
boolean
Throws:
SftpStatusException
SshException

pwd

String pwd()

Returns the absolute path name of the current remote working directory.

Returns:
the absolute path of the remote working directory.

ls

SftpFile[] ls()
              throws SftpStatusException,
                     SshException

List the contents of the current remote working directory.

Returns a list of SftpFile instances for the current working directory.

Returns:
a list of SftpFile for the current working directory
Throws:
SftpStatusException
SshException

ls

SftpFile[] ls(String path)
              throws SftpStatusException,
                     SshException

List the contents remote directory.

Returns a list of SftpFile instances for the remote directory.

Parameters:
path - the path on the remote server to list
Returns:
a list of SftpFile for the remote directory
Throws:
SftpStatusException
SshException

lcd

void lcd(String path)
         throws SftpStatusException

Changes the local working directory.

Parameters:
path - the path to the new working directory
Throws:
SftpStatusException

lpwd

String lpwd()

Returns the absolute path to the local working directory.

Returns:
the absolute path of the local working directory.

get

SftpFileAttributes get(String path,
                       FileTransferProgress progress)
                       throws FileNotFoundException,
                              SftpStatusException,
                              SshException,
                              TransferCancelledException

Download the remote file to the local computer.

Parameters:
path - the path to the remote file
progress -
Returns:
the downloaded file's attributes
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

get

SftpFileAttributes get(String path,
                       FileTransferProgress progress,
                       boolean resume)
                       throws FileNotFoundException,
                              SftpStatusException,
                              SshException,
                              TransferCancelledException

Download the remote file to the local computer.

Parameters:
path - the path to the remote file
progress -
resume - attempt to resume a interrupted download
Returns:
the downloaded file's attributes
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

get

SftpFileAttributes get(String path,
                       boolean resume)
                       throws FileNotFoundException,
                              SftpStatusException,
                              SshException,
                              TransferCancelledException

Download the remote file to the local computer

Parameters:
path - the path to the remote file
resume - attempt to resume an interrupted download
Returns:
the downloaded file's attributes
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

get

SftpFileAttributes get(String path)
                       throws FileNotFoundException,
                              SftpStatusException,
                              SshException,
                              TransferCancelledException

Download the remote file to the local computer

Parameters:
path - the path to the remote file
Returns:
the downloaded file's attributes
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

get

SftpFileAttributes get(String remote,
                       String local,
                       FileTransferProgress progress)
                       throws FileNotFoundException,
                              SftpStatusException,
                              SshException,
                              TransferCancelledException

Download the remote file to the local computer. If the paths provided are not absolute the current working directory is used.

Parameters:
remote - the path/name of the remote file
local - the path/name to place the file on the local computer
progress -
Returns:
the downloaded file's attributes
Throws:
SftpStatusException
FileNotFoundException
SshException
TransferCancelledException

get

SftpFileAttributes get(String remote,
                       String local,
                       FileTransferProgress progress,
                       boolean resume)
                       throws FileNotFoundException,
                              SftpStatusException,
                              SshException,
                              TransferCancelledException

Download the remote file to the local computer. If the paths provided are not absolute the current working directory is used.

Parameters:
remote - the path/name of the remote file
local - the path/name to place the file on the local computer
progress -
resume - attempt to resume an interrupted download
Returns:
the downloaded file's attributes
Throws:
SftpStatusException
FileNotFoundException
SshException
TransferCancelledException

get

SftpFileAttributes get(String remote,
                       String local,
                       boolean resume)
                       throws FileNotFoundException,
                              SftpStatusException,
                              SshException,
                              TransferCancelledException
Download the remote file into the local file.

Parameters:
remote -
local -
resume - attempt to resume an interrupted download
Returns:
the downloaded file's attributes
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

get

SftpFileAttributes get(String remote,
                       String local)
                       throws FileNotFoundException,
                              SftpStatusException,
                              SshException,
                              TransferCancelledException
Download the remote file into the local file.

Parameters:
remote -
local -
Returns:
the downloaded file's attributes
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

get

SftpFileAttributes get(String remote,
                       OutputStream local,
                       FileTransferProgress progress)
                       throws SftpStatusException,
                              SshException,
                              TransferCancelledException

Download the remote file writing it to the specified OutputStream. The OutputStream is closed by this method even if the operation fails.

Parameters:
remote - the path/name of the remote file
local - the OutputStream to write
progress -
Returns:
the downloaded file's attributes
Throws:
SftpStatusException
SshException
TransferCancelledException

getFiles

SftpFile[] getFiles(String remote,
                    OutputStream local,
                    FileTransferProgress progress,
                    long position)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException
make local copies of some of the variables, then call getfilematches, which calls get on each file that matches the regexp remote.

Parameters:
remote -
local -
progress -
position -
Returns:
SftpFile[]
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

getFiles

SftpFile[] getFiles(String remote,
                    String local,
                    FileTransferProgress progress,
                    boolean resume)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException
make local copies of some of the variables, then call getfilematches, which calls get on each file that matches the regexp remote.

Parameters:
remote -
local -
progress -
resume -
Returns:
SftpFile[]
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

setRegularExpressionSyntax

void setRegularExpressionSyntax(int syntax)
sets the type of regular expression matching to perform on gets and puts

Parameters:
syntax - , NoSyntax for no regular expression matching, GlobSyntax for GlobSyntax, Perl5Syntax for Perl5Syntax

get

SftpFileAttributes get(String remote,
                       OutputStream local,
                       FileTransferProgress progress,
                       long position)
                       throws SftpStatusException,
                              SshException,
                              TransferCancelledException

Download the remote file writing it to the specified OutputStream. The OutputStream is closed by this method even if the operation fails.

Parameters:
remote - the path/name of the remote file
local - the OutputStream to write
progress -
position - the position within the file to start reading from
Returns:
the downloaded file's attributes
Throws:
SftpStatusException
SshException
TransferCancelledException

getInputStream

InputStream getInputStream(String remotefile,
                           long position)
                           throws SftpStatusException,
                                  SshException
Create an InputStream for reading a remote file.

Parameters:
remotefile -
position -
Returns:
InputStream
Throws:
SftpStatusException
SshException

getInputStream

InputStream getInputStream(String remotefile)
                           throws SftpStatusException,
                                  SshException
Create an InputStream for reading a remote file.

Parameters:
remotefile -
Returns:
InputStream
Throws:
SftpStatusException
SshException

get

SftpFileAttributes get(String remote,
                       OutputStream local,
                       long position)
                       throws SftpStatusException,
                              SshException,
                              TransferCancelledException
Download the remote file into an OutputStream.

Parameters:
remote -
local -
position - the position from which to start reading the remote file
Returns:
the downloaded file's attributes
Throws:
SftpStatusException
SshException
TransferCancelledException

get

SftpFileAttributes get(String remote,
                       OutputStream local)
                       throws SftpStatusException,
                              SshException,
                              TransferCancelledException
Download the remote file into an OutputStream.

Parameters:
remote -
local -
Returns:
the downloaded file's attributes
Throws:
SftpStatusException
SshException
TransferCancelledException

isClosed

boolean isClosed()

Returns the state of the SFTP client. The client is closed if the underlying session channel is closed. Invoking the quit method of this object will close the underlying session channel.

Returns:
true if the client is still connected, otherwise false

put

void put(String local,
         FileTransferProgress progress,
         boolean resume)
         throws FileNotFoundException,
                SftpStatusException,
                SshException,
                TransferCancelledException

Upload a file to the remote computer.

Parameters:
local - the path/name of the local file
progress -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

put

void put(String local,
         FileTransferProgress progress)
         throws FileNotFoundException,
                SftpStatusException,
                SshException,
                TransferCancelledException

Upload a file to the remote computer.

Parameters:
local - the path/name of the local file
progress -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

put

void put(String local)
         throws FileNotFoundException,
                SftpStatusException,
                SshException,
                TransferCancelledException
Upload a file to the remote computer

Parameters:
local -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

put

void put(String local,
         boolean resume)
         throws FileNotFoundException,
                SftpStatusException,
                SshException,
                TransferCancelledException
Upload a file to the remote computer

Parameters:
local -
resume - attempt to resume after an interrupted transfer
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

put

void put(String local,
         String remote,
         FileTransferProgress progress)
         throws FileNotFoundException,
                SftpStatusException,
                SshException,
                TransferCancelledException

Upload a file to the remote computer. If the paths provided are not absolute the current working directory is used.

Parameters:
local - the path/name of the local file
remote - the path/name of the destination file
progress -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

put

void put(String local,
         String remote,
         FileTransferProgress progress,
         boolean resume)
         throws FileNotFoundException,
                SftpStatusException,
                SshException,
                TransferCancelledException

Upload a file to the remote computer. If the paths provided are not absolute the current working directory is used.

Parameters:
local - the path/name of the local file
remote - the path/name of the destination file
progress -
resume - attempt to resume after an interrupted transfer
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

put

void put(String local,
         String remote,
         boolean resume)
         throws FileNotFoundException,
                SftpStatusException,
                SshException,
                TransferCancelledException
Upload a file to the remote computer

Parameters:
local -
remote -
resume - attempt to resume after an interrupted transfer
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

put

void put(String local,
         String remote)
         throws FileNotFoundException,
                SftpStatusException,
                SshException,
                TransferCancelledException
Upload a file to the remote computer

Parameters:
local -
remote -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

put

void put(InputStream in,
         String remote,
         FileTransferProgress progress)
         throws SftpStatusException,
                SshException,
                TransferCancelledException

Upload a file to the remote computer reading from the specified InputStream . The InputStream is closed, even if the operation fails.

Parameters:
in - the InputStream being read
remote - the path/name of the destination file
progress -
Throws:
SftpStatusException
SshException
TransferCancelledException

put

void put(InputStream in,
         String remote,
         FileTransferProgress progress,
         long position)
         throws SftpStatusException,
                SshException,
                TransferCancelledException
Throws:
SftpStatusException
SshException
TransferCancelledException

getOutputStream

OutputStream getOutputStream(String remotefile)
                             throws SftpStatusException,
                                    SshException
Create an OutputStream for writing to a remote file.

Parameters:
remotefile -
Returns:
OutputStream
Throws:
SftpStatusException
SshException

put

void put(InputStream in,
         String remote,
         long position)
         throws SftpStatusException,
                SshException,
                TransferCancelledException
Upload the contents of an InputStream to the remote computer.

Parameters:
in -
remote -
position -
Throws:
SftpStatusException
SshException
TransferCancelledException

put

void put(InputStream in,
         String remote)
         throws SftpStatusException,
                SshException,
                TransferCancelledException
Upload the contents of an InputStream to the remote computer.

Parameters:
in -
remote -
Throws:
SftpStatusException
SshException
TransferCancelledException

chown

void chown(String uid,
           String path)
           throws SftpStatusException,
                  SshException

Sets the user ID to owner for the file or directory.

Parameters:
uid - numeric user id of the new owner
path - the path to the remote file/directory
Throws:
SftpStatusException
SshException
TransferCancelledException

chgrp

void chgrp(String gid,
           String path)
           throws SftpStatusException,
                  SshException

Sets the group ID for the file or directory.

Parameters:
gid - the numeric group id for the new group
path - the path to the remote file/directory
Throws:
SftpStatusException
SshException

chmod

void chmod(int permissions,
           String path)
           throws SftpStatusException,
                  SshException

Changes the access permissions or modes of the specified file or directory.

Modes determine who can read, change or execute a file.

 Absolute modes are octal numbers specifying the complete list of
 attributes for the files; you specify attributes by OR'ing together
 these bits.
 
 0400       Individual read
 0200       Individual write
 0100       Individual execute (or list directory)
 0040       Group read
 0020       Group write
 0010       Group execute
 0004       Other read
 0002       Other write
 0001       Other execute
 

Parameters:
permissions - the absolute mode of the file/directory
path - the path to the file/directory on the remote server
Throws:
SftpStatusException
SshException

umask

void umask(String umask)
           throws SshException
Sets the umask for this client.
 To give yourself full permissions for both files and directories and
 prevent the group and other users from having access:
 
   umask("077");
 
 This subtracts 077 from the system defaults for files and directories
 666 and 777. Giving a default access permissions for your files of
 600 (rw-------) and for directories of 700 (rwx------).
 
 To give all access permissions to the group and allow other users read
 and execute permission:
 
   umask("002");
 
 This subtracts 002 from the system defaults to give a default access permission
 for your files of 664 (rw-rw-r--) and for your directories of 775 (rwxrwxr-x).
 
 To give the group and other users all access except write access:
 
   umask("022");
 
 This subtracts 022 from the system defaults to give a default access permission
 for your files of 644 (rw-r--r--) and for your directories of 755 (rwxr-xr-x).
 

Parameters:
umask -
Throws:
SshException

rename

void rename(String oldpath,
            String newpath)
            throws SftpStatusException,
                   SshException

Rename a file on the remote computer.

Parameters:
oldpath - the old path
newpath - the new path
Throws:
SftpStatusException
SshException

rm

void rm(String path)
        throws SftpStatusException,
               SshException

Remove a file or directory from the remote computer.

Parameters:
path - the path of the remote file/directory
Throws:
SftpStatusException
SshException

rm

void rm(String path,
        boolean force,
        boolean recurse)
        throws SftpStatusException,
               SshException
Remove a file or directory on the remote computer with options to force deletion of existing files and recursion.

Parameters:
path -
force -
recurse -
Throws:
SftpStatusException
SshException

symlink

void symlink(String path,
             String link)
             throws SftpStatusException,
                    SshException

Create a symbolic link on the remote computer.

Parameters:
path - the path to the existing file
link - the new link
Throws:
SftpStatusException
SshException

stat

SftpFileAttributes stat(String path)
                        throws SftpStatusException,
                               SshException

Returns the attributes of the file from the remote computer.

Parameters:
path - the path of the file on the remote computer
Returns:
the attributes
Throws:
SftpStatusException
SshException
See Also:
setAttributes(String, SftpFileAttributes)

getAbsolutePath

String getAbsolutePath(String path)
                       throws SftpStatusException,
                              SshException
Get the absolute path for a file.

Parameters:
path -
Returns:
String
Throws:
SftpStatusException
SshException

quit

void quit()
          throws SshException

Close the SFTP client.

Throws:
SshException

exit

void exit()
          throws SshException

Close the SFTP client.

Throws:
SshException

copyLocalDirectory

DirectoryOperation copyLocalDirectory(String localdir,
                                      String remotedir,
                                      boolean recurse,
                                      boolean sync,
                                      boolean commit,
                                      FileTransferProgress progress)
                                      throws FileNotFoundException,
                                             SftpStatusException,
                                             SshException,
                                             TransferCancelledException
Copy the contents of a local directory into a remote remote directory.

Parameters:
localdir - the path to the local directory
remotedir - the remote directory which will receive the contents
recurse - recurse through child folders
sync - synchronize the directories by removing files on the remote server that do not exist locally
commit - actually perform the operation. If false a DirectoryOperation will be returned so that the operation can be evaluated and no actual files will be created/transfered.
progress -
Returns:
DirectoryOperation
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

copyRemoteDirectory

DirectoryOperation copyRemoteDirectory(String remotedir,
                                       String localdir,
                                       boolean recurse,
                                       boolean sync,
                                       boolean commit,
                                       FileTransferProgress progress)
                                       throws FileNotFoundException,
                                              SftpStatusException,
                                              SshException,
                                              TransferCancelledException
Copy the contents of a remote directory to a local directory

Parameters:
remotedir - the remote directory whose contents will be copied.
localdir - the local directory to where the contents will be copied
recurse - recurse into child folders
sync - synchronized the directories by removing files and directories that do not exist on the remote server.
commit - actually perform the operation. If false the operation will be processed and a DirectoryOperation will be returned without actually transfering any files.
progress -
Returns:
DirectoryOperation
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

getFiles

SftpFile[] getFiles(String remote)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException

Download the remote files to the local computer

When RegExpSyntax is set to NoSyntax the getFiles() methods act identically to the get() methods except for a different return type.

When RegExpSyntax is set to GlobSyntax or Perl5Syntax, getFiles() treats 'remote' as a regular expression, and gets all the files in 'remote''s parent directory that match the pattern. The default parent directory of remote is the remote cwd unless 'remote' contains file seperators(/).

Examples can be found in SftpConnect.java

Code Example:

 //change reg exp syntax from default SftpClient.NoSyntax (no reg exp matching) to SftpClient.GlobSyntax
 sftp.setRegularExpressionSyntax(SftpClient.GlobSyntax);
 //get all .doc files with 'rfc' in their names, in the 'docs/unsorted/' folder relative to the remote cwd, and copy them to the local cwd.
 sftp.getFiles("docs/unsorted/*rfc*.doc");
 

Parameters:
remote - the regular expression path to the remote file
Returns:
the downloaded files' attributes
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

getFiles

SftpFile[] getFiles(String remote,
                    boolean resume)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException

Download the remote files to the local computer

Parameters:
remote - the regular expression path to the remote file
resume - attempt to resume an interrupted download
Returns:
the downloaded files' attributes
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

getFiles

SftpFile[] getFiles(String remote,
                    FileTransferProgress progress)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException

Download the remote files to the local computer.

Parameters:
remote - the regular expression path to the remote file
progress -
Returns:
SftpFile[]
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

getFiles

SftpFile[] getFiles(String remote,
                    FileTransferProgress progress,
                    boolean resume)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException

Download the remote files to the local computer.

Parameters:
remote - the regular expression path to the remote file
progress -
resume - attempt to resume a interrupted download
Returns:
SftpFile[]
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

getFiles

SftpFile[] getFiles(String remote,
                    OutputStream local)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException
Download the remote files into an OutputStream.

Parameters:
remote -
local -
Returns:
SftpFile[]
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

getFiles

SftpFile[] getFiles(String remote,
                    OutputStream local,
                    FileTransferProgress progress)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException

Download the remote files writing it to the specified OutputStream. The OutputStream is closed by this mehtod even if the operation fails.

Parameters:
remote - the regular expression path/name of the remote file
local - the OutputStream to write
progress -
Returns:
SftpFile[]
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

getFiles

SftpFile[] getFiles(String remote,
                    OutputStream local,
                    long position)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException
Download the remote files into an OutputStream.

Parameters:
remote -
local -
position - the position from which to start reading the remote file
Returns:
SftpFile[]
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

getFiles

SftpFile[] getFiles(String remote,
                    String local)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException
Download the remote files into the local file.

Parameters:
remote -
local -
Returns:
SftpFile[]
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

getFiles

SftpFile[] getFiles(String remote,
                    String local,
                    boolean resume)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException
Download the remote files into the local file.

Parameters:
remote -
local -
resume - attempt to resume an interrupted download
Returns:
SftpFile[]
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

getFiles

SftpFile[] getFiles(String remote,
                    String local,
                    FileTransferProgress progress)
                    throws FileNotFoundException,
                           SftpStatusException,
                           SshException,
                           TransferCancelledException

Download the remote file to the local computer. If the paths provided are not absolute the current working directory is used.

Parameters:
remote - the regular expression path/name of the remote files
local - the path/name to place the file on the local computer
progress -
Returns:
SftpFile[]
Throws:
SftpStatusException
FileNotFoundException
SshException
TransferCancelledException

putFiles

void putFiles(InputStream in,
              String remote)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException

Upload the contents of an InputStream to the remote computer.

Parameters:
in -
remote -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

putFiles

void putFiles(InputStream in,
              String remote,
              FileTransferProgress progress)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException

Upload files to the remote computer reading from the specified InputStream . The InputStream is closed, even if the operation fails.

Parameters:
in - the InputStream being read
remote - the path/name of the destination file
progress -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

putFiles

void putFiles(InputStream in,
              String remote,
              FileTransferProgress progress,
              long position)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException
Throws:
FileNotFoundException
SftpStatusException
SshException
TransferCancelledException

putFiles

void putFiles(InputStream in,
              String remote,
              long position)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException
Upload the contents of an InputStream to the remote computer.

Parameters:
in -
remote -
position -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

putFiles

void putFiles(String local)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException

Upload the contents of an InputStream to the remote computer.

When RegExpSyntax is set to NoSyntax the putFiles() methods act identically to the put() methods except for a different return type.

When RegExpSyntax is set to GlobSyntax or Perl5Syntax, putFiles() treats 'local' as a regular expression, and gets all the files in 'local''s parent directory that match the pattern. The default parent directory of local is the local cwd unless 'local' contains file seperators.

Examples can be found in SftpConnect.java

Code Example:

 //change reg exp syntax from default SftpClient.NoSyntax (no reg exp matching) to SftpClient.GlobSyntax
 sftp.setRegularExpressionSyntax(SftpClient.GlobSyntax);
 //put all .doc files with 'rfc' in their names, in the 'docs/unsorted/' folder relative to the local cwd, and copy them to the remote cwd.
 sftp.putFiles("docs/unsorted/*rfc*.doc");
 

Parameters:
local -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

putFiles

void putFiles(String local,
              boolean resume)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException
Upload files to the remote computer

Parameters:
local -
resume - attempt to resume after an interrupted transfer
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

putFiles

void putFiles(String local,
              FileTransferProgress progress)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException

Upload files to the remote computer

Parameters:
local - the regular expression path/name of the local files
progress -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

putFiles

void putFiles(String local,
              FileTransferProgress progress,
              boolean resume)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException

Upload files to the remote computer

Parameters:
local - the regular expression path/name of the local files
progress -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

putFiles

void putFiles(String local,
              String remote)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException
Upload files to the remote computer

Parameters:
local -
remote -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

putFiles

void putFiles(String local,
              String remote,
              boolean resume)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException
Upload files to the remote computer

Parameters:
local -
remote -
resume - attempt to resume after an interrupted transfer
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

putFiles

void putFiles(String local,
              String remote,
              FileTransferProgress progress)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException

Upload files to the remote computer. If the paths provided are not absolute the current working directory is used.

Parameters:
local - the regular expression path/name of the local files
remote - the path/name of the destination file
progress -
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

putFiles

void putFiles(String local,
              String remote,
              FileTransferProgress progress,
              boolean resume)
              throws FileNotFoundException,
                     SftpStatusException,
                     SshException,
                     TransferCancelledException
make local copies of some of the variables, then call putfilematches, which calls "put" on each file that matches the regexp local.

Parameters:
local - the regular expression path/name of the local files
remote - the path/name of the destination file
progress -
resume - attempt to resume after an interrupted transfer
Throws:
SftpStatusException
SshException
TransferCancelledException
FileNotFoundException

getFile

SftpFile getFile(String path)
                 throws SshException,
                        SftpStatusException
Throws:
SshException
SftpStatusException

getCharsetEncoding

String getCharsetEncoding()

getVersion

int getVersion()

setAttributes

void setAttributes(String path,
                   SftpFileAttributes attrs)
                   throws SftpStatusException,
                          SshException

Updates a file's attributes. Note, this may not be supported by the implementation (e.g. if the SCP fallback is in use), so clients should catch the UnsupportedOperationException and react accordingly.

Parameters:
path - the path of the file
attrs - the attributes to set
Throws:
SftpStatusException
SshException
UnsupportedOperationException - if attributes cannot be set (e.g. using SCP fallback)
See Also:
stat(String)


Copyright © 2012. All Rights Reserved.