public class SftpClient extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
CHANNEL_SFTP |
static String |
PREFERRED_AUTHENTICATION_METHODS |
static String |
STRICT_HOST_KEY_CHECKING |
| Constructor and Description |
|---|
SftpClient(String host,
int port,
com.google.common.base.Supplier<com.jcraft.jsch.JSch> jSchSupplier)
Creates a new instance which connects to a server on a given
host and port |
| Modifier and Type | Method and Description |
|---|---|
void |
changeWorkingDirectory(String path)
Changes the current working directory to
wd |
void |
deleteDirectory(String path)
Deletes the directory at
path. |
void |
deleteFile(String path)
Deletes the file at the given
path |
void |
disconnect()
Closes the active session and severs the connection (if any of those were active)
|
protected RuntimeException |
exception(String message,
Exception cause) |
SftpFileAttributes |
getAttributes(Path path)
Gets the attributes for the file in the given {code path}
|
InputStream |
getFileContent(String path)
An
InputStream with the contents of the file at the given path |
String |
getHost() |
OutputStream |
getOutputStream(String path,
org.mule.extension.file.common.api.FileWriteMode mode)
Opens an
OutputStream which allows writing into the file pointed by path |
int |
getPort() |
String |
getWorkingDirectory() |
boolean |
isConnected() |
List<SftpFileAttributes> |
list(String path)
Lists the contents of the directory at the given
path |
void |
login(String user)
Performs a login operation for the given
user using the connection options and additional credentials optionally set
on this client |
void |
mkdir(String directoryName)
Creates a directory
|
void |
rename(String sourcePath,
String target)
Renames the file at
sourcePath to target |
void |
setConnectionTimeoutMillis(long connectionTimeoutMillis) |
void |
setIdentity(String identityFilePath,
String passphrase) |
void |
setKnownHostsFile(String knownHostsFile) |
void |
setPassword(String password) |
void |
setPreferredAuthenticationMethods(String preferredAuthenticationMethods) |
void |
write(String path,
InputStream stream,
org.mule.extension.file.common.api.FileWriteMode mode)
Writes the contents of the
stream into the file at the given path |
public static final String CHANNEL_SFTP
public static final String STRICT_HOST_KEY_CHECKING
public static final String PREFERRED_AUTHENTICATION_METHODS
public SftpClient(String host, int port, com.google.common.base.Supplier<com.jcraft.jsch.JSch> jSchSupplier)
host and porthost - the host addressport - the remote connection portjSchSupplier - a Supplier for obtaining a JSch clientpublic String getWorkingDirectory()
public void changeWorkingDirectory(String path)
wdpath - the new working directory pathpublic SftpFileAttributes getAttributes(Path path)
path - the file's pathSftpFileAttributes or null if the file doesn't exists.public void login(String user) throws IOException, com.jcraft.jsch.JSchException
user using the connection options and additional credentials optionally set
on this clientuser - the authentication userIOExceptioncom.jcraft.jsch.JSchExceptionpublic void rename(String sourcePath, String target) throws IOException
sourcePath to targetsourcePath - the path to the renamed filetarget - the new pathIOExceptionpublic void deleteFile(String path)
pathpath - the path to the file to be deletedpublic void disconnect()
public boolean isConnected()
public List<SftpFileAttributes> list(String path)
pathpath - the path to listList of . Might be empty but will never be nullpublic InputStream getFileContent(String path)
InputStream with the contents of the file at the given pathpath - the path to the file to readInputStreampublic void write(String path, InputStream stream, org.mule.extension.file.common.api.FileWriteMode mode) throws Exception
stream into the file at the given pathpath - the path to write intostream - the content to be writtenmode - the write modeException - if anything goes wrongpublic OutputStream getOutputStream(String path, org.mule.extension.file.common.api.FileWriteMode mode) throws Exception
OutputStream which allows writing into the file pointed by pathpath - the path to write intomode - the write modeOutputStreamExceptionpublic void mkdir(String directoryName)
directoryName - The directory nameIOException - If an error occurspublic void deleteDirectory(String path)
path.
The directory is expected to be empty
path - the path of the directory to be deletedpublic String getHost()
public void setPreferredAuthenticationMethods(String preferredAuthenticationMethods)
protected RuntimeException exception(String message, Exception cause)
public void setKnownHostsFile(String knownHostsFile)
public void setPassword(String password)
public int getPort()
public void setConnectionTimeoutMillis(long connectionTimeoutMillis)
Copyright © 2003–2017 MuleSoft, Inc.. All rights reserved.