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.
|
java.lang.String[] |
dir(java.lang.String directory,
java.io.FileFilter filter)
List a directory's contents
|
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) |
ensureNotNull, isAdditionaDebug, log, setAdditionalDebugpublic 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.SftpExceptionpublic SftpClient(java.net.InetAddress addr)
throws SftpException
addr - the remote ssh host.SftpExceptionpublic SftpClient(java.net.InetAddress addr,
int port,
int timeout)
throws SftpException
addr - the remote ssh host.port - the ssh port.timeout - the timeout;SftpExceptionpublic SftpClient(java.lang.String host,
int port,
int timeout)
throws SftpException
host - the hostport - the porttimeout - the timeout;SftpExceptionpublic 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;SftpExceptionpublic void connect(java.lang.String user,
java.lang.String password)
throws java.io.IOException,
FileTransferException
FileTransferClientuser - 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 directory,
java.io.FileFilter filter)
throws FileTransferException,
java.io.IOException
FileTransferClient
Note that although we use a standard FileFilter interface here operating on
File; it actually uses RemoteFile instead which overrides information
that can be obtained from the remote server. Other standard File operations will
not be supported, and may ultimately cause a runtime exception.
directory - the directory to list.filter - the filefilter mask to useFileTransferException - on FTP Specific exception error.java.io.IOException - on comms error.public java.lang.String[] dir(java.lang.String dirname,
boolean full)
throws java.io.IOException,
FileTransferException
FileTransferClientA 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
FileTransferClientFileTransferException - 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
FileTransferClientsrcStream - 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
FileTransferClientdestStream - 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
FileTransferClientremoteFile - 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
FileTransferClientremoteFile - 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
FileTransferClientfrom - 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
FileTransferClientdir - 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
FileTransferClientdir - 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
FileTransferClientdir - 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
FileTransferClientremoteFile - 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
FileTransferClientremoteFile - 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
FileTransferClientFtpExceptionpublic void setKeepAliveTimeout(long seconds)
throws FtpException
FileTransferClientseconds - time in secondsFtpExceptionpublic SftpClient withKeepAliveTimeout(long seconds) throws FtpException
FtpExceptionpublic SftpClient withAdditionalDebug(boolean onoff)
public boolean isConnected()
FileTransferClientpublic void setKnownHosts(java.lang.String knownHostsFilename)
throws SftpException
SftpException