org.apache.camel.component.file.remote
Class SftpOperations

java.lang.Object
  extended by org.apache.camel.component.file.remote.SftpOperations
All Implemented Interfaces:
GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>, RemoteFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>

public class SftpOperations
extends Object
implements RemoteFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>

SFTP remote file operations


Constructor Summary
SftpOperations()
           
 
Method Summary
 boolean buildDirectory(String directory, boolean absolute)
          Builds the directory structure.
 void changeCurrentDirectory(String path)
          Change the current remote directory
 void changeToParentDirectory()
          Change the current remote directory to the parent
 boolean connect(RemoteFileConfiguration configuration)
          Connects to the remote server
protected  com.jcraft.jsch.Session createSession(RemoteFileConfiguration configuration)
           
 boolean deleteFile(String name)
          Deletes the file name by name, relative to the current directory
 void disconnect()
          Disconnects from the remote server
 boolean existsFile(String name)
          Determines whether the files exists or not
 String getCurrentDirectory()
          Gets the current remote directory
 boolean isConnected()
          Returns whether we are connected to the remote server or not
 List<com.jcraft.jsch.ChannelSftp.LsEntry> listFiles()
          List the files in the current directory
 List<com.jcraft.jsch.ChannelSftp.LsEntry> listFiles(String path)
          List the files in the given remote directory
 boolean renameFile(String from, String to)
          Renames the file
 boolean retrieveFile(String name, Exchange exchange)
          Retrieves the file
 boolean sendNoop()
          Sends a noop command to the remote server
 boolean sendSiteCommand(String command)
          Sends a site command to the remote server
 void setEndpoint(GenericFileEndpoint endpoint)
          Sets the endpoint as some implementations need access to the endpoint and how its configured.
 boolean storeFile(String name, Exchange exchange)
          Stores the content as a new remote file (upload)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SftpOperations

public SftpOperations()
Method Detail

setEndpoint

public void setEndpoint(GenericFileEndpoint endpoint)
Description copied from interface: GenericFileOperations
Sets the endpoint as some implementations need access to the endpoint and how its configured.

Specified by:
setEndpoint in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Parameters:
endpoint - the endpoint

connect

public boolean connect(RemoteFileConfiguration configuration)
                throws GenericFileOperationFailedException
Description copied from interface: RemoteFileOperations
Connects to the remote server

Specified by:
connect in interface RemoteFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Parameters:
configuration - configuration
Returns:
true if connected
Throws:
GenericFileOperationFailedException - can be thrown

createSession

protected com.jcraft.jsch.Session createSession(RemoteFileConfiguration configuration)
                                         throws com.jcraft.jsch.JSchException
Throws:
com.jcraft.jsch.JSchException

isConnected

public boolean isConnected()
                    throws GenericFileOperationFailedException
Description copied from interface: RemoteFileOperations
Returns whether we are connected to the remote server or not

Specified by:
isConnected in interface RemoteFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Returns:
true if connected, false if not
Throws:
GenericFileOperationFailedException - can be thrown

disconnect

public void disconnect()
                throws GenericFileOperationFailedException
Description copied from interface: RemoteFileOperations
Disconnects from the remote server

Specified by:
disconnect in interface RemoteFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Throws:
GenericFileOperationFailedException - can be thrown

deleteFile

public boolean deleteFile(String name)
                   throws GenericFileOperationFailedException
Description copied from interface: GenericFileOperations
Deletes the file name by name, relative to the current directory

Specified by:
deleteFile in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Parameters:
name - name of the file
Returns:
true if deleted, false if not
Throws:
GenericFileOperationFailedException - can be thrown

renameFile

public boolean renameFile(String from,
                          String to)
                   throws GenericFileOperationFailedException
Description copied from interface: GenericFileOperations
Renames the file

Specified by:
renameFile in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Parameters:
from - original name
to - the new name
Returns:
true if renamed, false if not
Throws:
GenericFileOperationFailedException - can be thrown

buildDirectory

public boolean buildDirectory(String directory,
                              boolean absolute)
                       throws GenericFileOperationFailedException
Description copied from interface: GenericFileOperations
Builds the directory structure. Will test if the folder already exists.

Specified by:
buildDirectory in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Parameters:
directory - the directory path to build as a relative string name
absolute - wether the directory is an absolute or relative path
Returns:
true if build or already exists, false if not possible (could be lack of permissions)
Throws:
GenericFileOperationFailedException - can be thrown

getCurrentDirectory

public String getCurrentDirectory()
                           throws GenericFileOperationFailedException
Description copied from interface: GenericFileOperations
Gets the current remote directory

Specified by:
getCurrentDirectory in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Returns:
the current directory path
Throws:
GenericFileOperationFailedException - can be thrown

changeCurrentDirectory

public void changeCurrentDirectory(String path)
                            throws GenericFileOperationFailedException
Description copied from interface: GenericFileOperations
Change the current remote directory

Specified by:
changeCurrentDirectory in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Parameters:
path - the path to change to
Throws:
GenericFileOperationFailedException - can be thrown

changeToParentDirectory

public void changeToParentDirectory()
                             throws GenericFileOperationFailedException
Description copied from interface: GenericFileOperations
Change the current remote directory to the parent

Specified by:
changeToParentDirectory in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Throws:
GenericFileOperationFailedException - can be thrown

listFiles

public List<com.jcraft.jsch.ChannelSftp.LsEntry> listFiles()
                                                    throws GenericFileOperationFailedException
Description copied from interface: GenericFileOperations
List the files in the current directory

Specified by:
listFiles in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Returns:
a list of backing objects representing the files
Throws:
GenericFileOperationFailedException - can be thrown

listFiles

public List<com.jcraft.jsch.ChannelSftp.LsEntry> listFiles(String path)
                                                    throws GenericFileOperationFailedException
Description copied from interface: GenericFileOperations
List the files in the given remote directory

Specified by:
listFiles in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Parameters:
path - the remote directory
Returns:
a list of backing objects representing the files
Throws:
GenericFileOperationFailedException - can be thrown

retrieveFile

public boolean retrieveFile(String name,
                            Exchange exchange)
                     throws GenericFileOperationFailedException
Description copied from interface: GenericFileOperations
Retrieves the file

Specified by:
retrieveFile in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Parameters:
name - name of the file
exchange - stream to write the content of the file into
Returns:
true if file has been retrieved, false if not
Throws:
GenericFileOperationFailedException - can be thrown

storeFile

public boolean storeFile(String name,
                         Exchange exchange)
                  throws GenericFileOperationFailedException
Description copied from interface: GenericFileOperations
Stores the content as a new remote file (upload)

Specified by:
storeFile in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Parameters:
name - name of new file
exchange - with the content content of the file
Returns:
true if the file was stored, false if not
Throws:
GenericFileOperationFailedException - can be thrown

existsFile

public boolean existsFile(String name)
                   throws GenericFileOperationFailedException
Description copied from interface: GenericFileOperations
Determines whether the files exists or not

Specified by:
existsFile in interface GenericFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Parameters:
name - name of the file
Returns:
true if exists, false if not
Throws:
GenericFileOperationFailedException - can be thrown

sendNoop

public boolean sendNoop()
                 throws GenericFileOperationFailedException
Description copied from interface: RemoteFileOperations
Sends a noop command to the remote server

Specified by:
sendNoop in interface RemoteFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Returns:
true if the noop was a success, false otherwise
Throws:
GenericFileOperationFailedException - can be thrown

sendSiteCommand

public boolean sendSiteCommand(String command)
                        throws GenericFileOperationFailedException
Description copied from interface: RemoteFileOperations
Sends a site command to the remote server

Specified by:
sendSiteCommand in interface RemoteFileOperations<com.jcraft.jsch.ChannelSftp.LsEntry>
Parameters:
command - the command
Returns:
true if the command was a success, false otherwise
Throws:
GenericFileOperationFailedException - can be thrown


Apache CAMEL