public class SftpClient extends FileTransferClientImp
FileTransferClient
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
NO_KERBEROS_AUTH |
static java.lang.String |
SSH_PREFERRED_AUTHENTICATIONS |
logR
Constructor and Description |
---|
SftpClient(java.net.InetAddress addr)
Constructor assuming the default SSH port.
|
SftpClient(java.net.InetAddress addr,
int port,
int timeout)
Constructor.
|
SftpClient(java.lang.String host)
Constructor assuming the default SSH port.
|
SftpClient(java.lang.String host,
int port,
int timeout)
Constructor.
|
SftpClient(java.lang.String host,
int port,
int timeout,
java.io.File knownHostsFile,
ConfigBuilder configBuilder)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
chdir(java.lang.String dir)
Change the remote working directory to that supplied
|
void |
connect(java.lang.String user,
byte[] prvKey,
byte[] prvKeyPwd)
Connect and login into an account on the SFTP server.
|
void |
connect(java.lang.String user,
java.lang.String password)
Connect and login into an account on the FTP server.
|
void |
delete(java.lang.String remoteFile)
Delete the specified remote file
|
java.lang.String[] |
dir(java.lang.String dirname,
boolean full)
List a directory's contents as an array of strings.
|
void |
disconnect()
Quit the FTP session
|
void |
get(java.io.OutputStream destStream,
java.lang.String remoteFile)
Get data from the FTP server.
|
byte[] |
get(java.lang.String remoteFile)
Get data from the FTP server.
|
long |
getKeepAliveTimeout()
Get the time to wait between sending control connection keepalive messages.
|
boolean |
isConnected()
Check if this client is still connected to its target
Any errors return a false
This is used to check cached connections are still working
|
long |
lastModified(java.lang.String remoteFile)
Return the last modified time for the given path.
|
java.util.Date |
lastModifiedDate(java.lang.String remoteFile)
Return the last modified date for the given path.
|
void |
mkdir(java.lang.String dir)
Create the specified remote working directory
|
void |
put(java.io.InputStream srcStream,
java.lang.String remoteFile,
boolean append)
Put a stream of data onto the FTP server.
|
void |
rename(java.lang.String from,
java.lang.String to)
Rename a file or directory
|
void |
rmdir(java.lang.String dir)
Delete the specified remote working directory
|
void |
setKeepAliveTimeout(long seconds)
Set the time to wait between sending control connection keepalive messages when processing file upload or download.
|
void |
setKnownHosts(java.lang.String knownHostsFilename) |
SftpClient |
withAdditionalDebug(boolean onoff) |
SftpClient |
withKeepAliveTimeout(long seconds) |
dir, dir, dir, dir, get, isAdditionaDebug, log, put, put, put, put, put, setAdditionalDebug
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
public static final java.lang.String NO_KERBEROS_AUTH
public static final java.lang.String SSH_PREFERRED_AUTHENTICATIONS
public SftpClient(java.lang.String host) throws SftpException
host
- the remote ssh host.SftpException
public SftpClient(java.net.InetAddress addr) throws SftpException
addr
- the remote ssh host.SftpException
public SftpClient(java.net.InetAddress addr, int port, int timeout) throws SftpException
addr
- the remote ssh host.port
- the ssh port.timeout
- the timeout;SftpException
public SftpClient(java.lang.String host, int port, int timeout) throws SftpException
host
- the hostport
- the porttimeout
- the timeout;SftpException
public SftpClient(java.lang.String host, int port, int timeout, java.io.File knownHostsFile, ConfigBuilder configBuilder) throws SftpException
host
- the hostport
- the porttimeout
- the timeout;configBuilder
- any required behaviour for this client;SftpException
public void connect(java.lang.String user, java.lang.String password) throws java.io.IOException, FileTransferException
FileTransferClient
user
- user namepassword
- user's passwordFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occursFileTransferClient.connect(java.lang.String, java.lang.String)
public void connect(java.lang.String user, byte[] prvKey, byte[] prvKeyPwd) throws FileTransferException
user
- user nameprvKey
- private key as part of public/private key pairprvKeyPwd
- the password for accessing the private key.FileTransferException
- if an FTP specific exception occurspublic java.lang.String[] dir(java.lang.String dirname, boolean full) throws java.io.IOException, FileTransferException
FileTransferClient
A detailed listing is available, otherwise just filenames are provided. The detailed listing varies in details depending on OS and FTP server. Note that a full listing can be used on a file name to obtain information about a file. The special files "." and ".." are ignored.
dirname
- name of directory (not a file mask)full
- true if detailed listing required false otherwiseFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occursFileTransferClient.dir(java.lang.String, boolean)
public void disconnect() throws java.io.IOException, FileTransferException
FileTransferClient
FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occursFileTransferClient.disconnect()
public void put(java.io.InputStream srcStream, java.lang.String remoteFile, boolean append) throws java.io.IOException, FileTransferException
FileTransferClient
srcStream
- input stream of data to putremoteFile
- name of remote fileappend
- true if appending, false otherwiseFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occursFileTransferClient.put(java.io.InputStream, java.lang.String, boolean)
public void get(java.io.OutputStream destStream, java.lang.String remoteFile) throws java.io.IOException, FileTransferException
FileTransferClient
destStream
- data stream to write data toremoteFile
- name of remote fileFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occursFileTransferClient.get(java.io.OutputStream, java.lang.String)
public byte[] get(java.lang.String remoteFile) throws java.io.IOException, FileTransferException
FileTransferClient
remoteFile
- name of remote fileFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occursFileTransferClient.get(java.lang.String)
public void delete(java.lang.String remoteFile) throws java.io.IOException, FileTransferException
FileTransferClient
remoteFile
- name of remote file to deleteFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occursFileTransferClient.delete(java.lang.String)
public void rename(java.lang.String from, java.lang.String to) throws java.io.IOException, FileTransferException
FileTransferClient
from
- name of file or directory to renameto
- intended nameFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void rmdir(java.lang.String dir) throws java.io.IOException, FileTransferException
FileTransferClient
dir
- name of remote directory to deleteFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void mkdir(java.lang.String dir) throws java.io.IOException, FileTransferException
FileTransferClient
dir
- name of remote directory to createFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic void chdir(java.lang.String dir) throws java.io.IOException, FileTransferException
FileTransferClient
dir
- name of remote directory to change toFileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occurspublic java.util.Date lastModifiedDate(java.lang.String remoteFile) throws java.io.IOException, FileTransferException
FileTransferClient
remoteFile
- the path to the filename.FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occursFileTransferClient.lastModifiedDate(java.lang.String)
public long lastModified(java.lang.String remoteFile) throws java.io.IOException, FileTransferException
FileTransferClient
remoteFile
- the path to the filename.FileTransferException
- if an FTP specific exception occursjava.io.IOException
- if a comms error occursFileTransferClient.lastModified(java.lang.String)
public long getKeepAliveTimeout() throws FtpException
FileTransferClient
FtpException
public void setKeepAliveTimeout(long seconds) throws FtpException
FileTransferClient
seconds
- time in secondsFtpException
public SftpClient withKeepAliveTimeout(long seconds) throws FtpException
FtpException
public SftpClient withAdditionalDebug(boolean onoff)
public boolean isConnected()
FileTransferClient
public void setKnownHosts(java.lang.String knownHostsFilename) throws SftpException
SftpException