org.mule.transport.sftp
Class SftpClient

java.lang.Object
  extended by org.mule.transport.sftp.SftpClient

public class SftpClient
extends Object

SftpClient Wrapper around jsch sftp library. Provides access to basic sftp commands.


Field Summary
static String CHANNEL_SFTP
           
static String STRICT_HOST_KEY_CHECKING
           
 
Constructor Summary
SftpClient(String host)
           
SftpClient(String host, SftpNotifier notifier)
           
 
Method Summary
 void changeWorkingDirectory(String wd)
           
 void chmod(String path, int permissions)
           
 void createSftpDirIfNotExists(ImmutableEndpoint endpoint, String newDir)
          Creates the directory if it not already exists.
 void deleteDirectory(String path)
           
 void deleteFile(String fileName)
           
 void disconnect()
           
 String duplicateHandling(String destDir, String filename, String duplicateHandling)
           
 String getAbsolutePath(String path)
          Converts a relative path to an absolute path according to http://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04.
 com.jcraft.jsch.ChannelSftp getChannelSftp()
           
 String getHost()
           
 long getLastModifiedTime(String filename)
           
 long getSize(String filename)
           
 boolean isConnected()
           
 String[] listDirectories()
           
 String[] listDirectories(String path)
           
 String[] listFiles()
           
 String[] listFiles(String path)
           
 void login(String user, String password)
           
 void login(String user, String identityFile, String passphrase)
           
 void mkdir(String directoryName)
          Creates a directory
 void recursivelyDeleteDirectory(String dir)
           
 void rename(String filename, String dest)
           
 InputStream retrieveFile(String fileName)
           
 void setNotifier(SftpNotifier notifier)
           
 void setPort(int port)
           
 void storeFile(String fileName, InputStream stream)
           
 void storeFile(String fileNameLocal, String fileNameRemote)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHANNEL_SFTP

public static final String CHANNEL_SFTP
See Also:
Constant Field Values

STRICT_HOST_KEY_CHECKING

public static final String STRICT_HOST_KEY_CHECKING
See Also:
Constant Field Values
Constructor Detail

SftpClient

public SftpClient(String host)

SftpClient

public SftpClient(String host,
                  SftpNotifier notifier)
Method Detail

changeWorkingDirectory

public void changeWorkingDirectory(String wd)
                            throws IOException
Throws:
IOException

getAbsolutePath

public String getAbsolutePath(String path)
Converts a relative path to an absolute path according to http://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04.

Parameters:
path - relative path
Returns:
Absolute path

login

public void login(String user,
                  String password)
           throws IOException
Throws:
IOException

login

public void login(String user,
                  String identityFile,
                  String passphrase)
           throws IOException
Throws:
IOException

setPort

public void setPort(int port)

rename

public void rename(String filename,
                   String dest)
            throws IOException
Throws:
IOException

deleteFile

public void deleteFile(String fileName)
                throws IOException
Throws:
IOException

disconnect

public void disconnect()

isConnected

public boolean isConnected()

listFiles

public String[] listFiles()
                   throws IOException
Throws:
IOException

listFiles

public String[] listFiles(String path)
                   throws IOException
Throws:
IOException

listDirectories

public String[] listDirectories()
                         throws IOException
Throws:
IOException

listDirectories

public String[] listDirectories(String path)
                         throws IOException
Throws:
IOException

retrieveFile

public InputStream retrieveFile(String fileName)
                         throws IOException
Throws:
IOException

storeFile

public void storeFile(String fileName,
                      InputStream stream)
               throws IOException
Throws:
IOException

storeFile

public void storeFile(String fileNameLocal,
                      String fileNameRemote)
               throws IOException
Throws:
IOException

getSize

public long getSize(String filename)
             throws IOException
Throws:
IOException

getLastModifiedTime

public long getLastModifiedTime(String filename)
                         throws IOException
Parameters:
filename - File name
Returns:
Number of seconds since the file was written to
Throws:
IOException - If an error occurs

mkdir

public void mkdir(String directoryName)
           throws IOException
Creates a directory

Parameters:
directoryName - The directory name
Throws:
IOException - If an error occurs

deleteDirectory

public void deleteDirectory(String path)
                     throws IOException
Throws:
IOException

getChannelSftp

public com.jcraft.jsch.ChannelSftp getChannelSftp()
Returns:
the ChannelSftp - useful for some tests

createSftpDirIfNotExists

public void createSftpDirIfNotExists(ImmutableEndpoint endpoint,
                                     String newDir)
                              throws IOException
Creates the directory if it not already exists. TODO: check if the SftpUtil & SftpClient methods can be merged Note, this method is synchronized because it in rare cases can be called from two threads at the same time and thus cause an error.

Parameters:
endpoint -
newDir -
Throws:
IOException

duplicateHandling

public String duplicateHandling(String destDir,
                                String filename,
                                String duplicateHandling)
                         throws IOException
Throws:
IOException

chmod

public void chmod(String path,
                  int permissions)
           throws com.jcraft.jsch.SftpException
Throws:
com.jcraft.jsch.SftpException

setNotifier

public void setNotifier(SftpNotifier notifier)

getHost

public String getHost()

recursivelyDeleteDirectory

public void recursivelyDeleteDirectory(String dir)
                                throws IOException
Throws:
IOException


Copyright © 2003-2012 MuleSoft, Inc.. All Rights Reserved.