public class Sftp
extends java.lang.Object
implements java.lang.AutoCloseable
Example usage:
// connection information String hostname = "10.0.0.1"; String username = "jsmith"; String password = "secret"; // create com.jscape.inet.ssh.util.SshParameters instance SshParameters params = new SshParameters(hostname,username,password); // set key exchanges, ciphers, macs and compressions if needed SshConfiguration sshConfiguration = SshConfiguration.configurationFor(new ComponentClientKeyExchangeFactory(ClientKeyExchanges.DH_GROUP_SHA256, ClientKeyExchanges.DH_GROUP_SHA1), new JceEncryptionFactory(JceEncryptions.AES256_CBC, JceEncryptions.BLOWFISH_CBC), new JceMacFactory(JceMacs.HMAC_SHA2_512, JceMacs.HMAC_SHA1), new ComponentCompressionFactory(Compressions.NONE)); SftpConfiguration configuration = new SftpConfiguration(sshConfiguration, true); // create Sftp instance Sftp sftp = new Sftp(params, configuration); // connect to SSH server sftp.connect(); // print directory listing to console System.out.println(sftp.getDirListingAsString()); // disconnect from SSH server sftp.disconnect();
Modifier and Type | Class and Description |
---|---|
static class |
Sftp.DirectoryService |
class |
Sftp.DownloadDirectoryOperation |
static class |
Sftp.DownloadFileOperation |
static class |
Sftp.RecursiveDeleteOperation |
static class |
Sftp.RecursiveFileListOperation |
static interface |
Sftp.RemoteDirectory |
static class |
Sftp.SftpPipedInputStream |
static class |
Sftp.SftpPipedOutputStream |
static class |
Sftp.UploadDirectoryOperation |
static class |
Sftp.UploadFileOperation |
Modifier and Type | Field and Description |
---|---|
static int |
ASCII |
static int |
AUTO |
static int |
BINARY |
static int |
DEFAULT_VERSION |
Constructor and Description |
---|
Sftp(SshParameters parameters)
Creates a new client instance.
|
Sftp(SshParameters parameters,
java.io.File currentLocalDirectory)
Creates a new client instance.
|
Sftp(SshParameters parameters,
java.io.File currentLocalDirectory,
SftpConfiguration configuration)
Creates a new SFTP client instance.
|
Sftp(SshParameters parameters,
SftpConfiguration configuration)
Creates a new client instance.
|
Sftp(SshParameters parameters,
SftpConfiguration configuration,
int version,
java.io.File currentLocalDirectory,
java.lang.String currentRemoteDirectory,
int transferBufferSizeBytes,
int pipelineWindowSize,
java.util.logging.Logger logger)
Creates a new client instance.
|
Modifier and Type | Method and Description |
---|---|
void |
abortDownloadThread(java.lang.String remoteFile)
Cancel the given file transfer thread.
|
void |
abortDownloadThreads()
Abort download threads.
|
void |
abortUploadThread(java.lang.String remoteFile) |
void |
abortUploadThreads()
Abort all upload threads.
|
void |
addSftpListener(SftpListener listener)
Adds event listener.
|
static void |
clearProxySettings()
Clears proxy server values.
|
void |
close() |
Sftp |
connect()
Establishes secure connection with SSH server.
|
Sftp |
copy()
Returns a copy of current instance.
|
void |
createSymbolicLink(java.lang.String remoteLinkFile,
java.lang.String remoteTargetFile)
Creates a symbolc link.
|
void |
deleteDir(java.lang.String remoteDirectory)
Deletes directory from SSH server.
|
void |
deleteDir(java.lang.String remoteDirectory,
boolean recursive)
Deletes directory from SSH server recursively.
|
void |
deleteFile(java.lang.String remoteFile)
Deletes file from SSH server.
|
void |
disableFileAccessLogging()
Turn off file access logging.
|
void |
disconnect()
Disconnects from the remote host.
|
void |
download(java.io.OutputStream out,
java.lang.String remoteFile)
Downloads file from SSH server and writes to specified
OutputStream . |
void |
download(java.io.OutputStream out,
java.lang.String remoteFile,
long remoteFileOffset)
Downloads file from SSH server and writes to specified
OutputStream . |
java.io.File |
download(java.lang.String remoteFile)
Downloads file from SSH server.
|
java.io.File |
download(java.lang.String localFile,
java.lang.String remoteFile)
Downloads the file from SSH server.
|
void |
downloadDir(java.lang.String remoteDirectory)
Downloads remote directory and contents recursively from SSH server.
|
void |
downloadDir(java.lang.String remoteDirectory,
int retryAttempts)
Downloads remote directory and contents from SSH server.
|
void |
downloadDir(java.lang.String remoteDirectory,
int retryAttempts,
int retryInterval)
Downloads remote directory and contents from SSH server.
|
void |
downloadDir(java.lang.String remoteDirectory,
int retryAttempts,
int retryInterval,
int threadCount)
Downloads remote directory and contents from SSH server.
|
void |
enableFileAccessLogging()
Turn on file access logging.
|
boolean |
exists(java.lang.String remotePath)
Checks if path is valid, i.e.
|
int |
getBlockSize()
Gets upload block size.
|
SftpConfiguration |
getConfiguration()
Returns the current configuration.
|
boolean |
getDebug()
Returns debug mode flag.
|
java.io.PrintStream |
getDebugStream()
Returns current debug stream if any.
|
com.jscape.util.file.PosixFilePermissions |
getDefaultDirectoryPermissions() |
java.lang.String |
getDir()
Gets current working directory of SSH server.
|
java.util.Enumeration |
getDirListing()
Gets directory listing from SSH server.
|
java.util.Enumeration |
getDirListing(java.lang.String regex)
Gets directory listing from SSH server where file names matches
the regular expression.
|
java.util.Enumeration |
getDirListing(java.lang.String remoteDirectory,
java.lang.String regex) |
java.lang.String |
getDirListingAsString()
Gets directory listing of files on SSH server.
|
java.lang.String |
getDirListingAsString(java.lang.String regex)
Gets directory listing from SSH server where file names matches
the regular expression.
|
int |
getDownloadBlockSize()
Gets the current download buffer size.
|
java.util.Date |
getFileAccessTimestamp(java.lang.String remoteFile)
Gets access date/timestamp of remote file from SSH server.
|
java.util.Date |
getFileCreationTimestamp(java.lang.String remoteFile)
Gets creation date/timestamp of remote file from SSH server.
|
int |
getFilePermissions(java.lang.String remoteFile)
Gets remote file permissions in UNIX chmod format (644, 777).
|
long |
getFilesize(java.lang.String remoteFile)
Gets filesize of remote file from SSH server.
|
java.util.Date |
getFileTimestamp(java.lang.String remoteFile)
Gets modification date/timestamp of remote file from SSH server.
|
SshHostKeys |
getHostKeys()
Returns SSH host keys for further use.
|
java.io.InputStream |
getInputStream(java.lang.String remoteFile,
long remoteFileOffset) |
java.lang.String |
getLineTerminator()
Gets destination line terminator used in ASCII file transfers.
|
java.io.File |
getLocalDir()
Gets local directory to be used in SSH session.
|
java.util.Enumeration |
getLocalDirListing()
Gets local directory listing.
|
java.util.Enumeration |
getLocalDirListing(java.lang.String regex)
Gets local directory listing.
|
java.util.logging.Level |
getLogLevel()
Returns current log level.
|
int |
getMode()
Gets data transfer mode for current session.
|
java.util.Enumeration |
getNameListing()
Gets directory listing of files on SSH server.
|
java.util.Enumeration |
getNameListing(java.lang.String regex)
Gets the remote directory content names.
|
java.io.OutputStream |
getOutputStream(java.lang.String remoteFile,
long remoteFileOffset,
boolean append) |
SshParameters |
getParameters() |
int |
getPipelineWindowSize()
Sets the window size (a number of request packets without response) in pipeline transfer mode.
|
java.lang.String |
getRealPath(java.lang.String remotePath)
Gets real server path.
|
int |
getRecursiveDirectoryFileCount(java.lang.String remoteDirectory)
Get size of all files rescursively in a given remote directory.
|
long |
getRecursiveDirectorySize(java.lang.String remoteDirectory)
Get size of all files recursively in a given remote directory.
|
java.util.Vector |
getRemoteFileList(java.lang.String remoteDirectory)
Gets a remote file list fron the current directory.
|
SshParameters |
getSshParameters()
Get SSH parameters.
|
java.lang.String |
getSymbolicLinkTargetPath(java.lang.String remoteFile)
Returns remote symbolic link target path.
|
long |
getTimeout()
Deprecated.
use getParameters()
|
com.jscape.util.file.UnixFileType |
getType(java.lang.String remotePath)
Returns Unix file type of the specified remote path.
|
int |
getUploadBlockSize()
Gets the current upload buffer size.
|
int |
getVersion()
Returns current target SFTP version.
|
void |
interrupt()
Interrupts the current data transfer and sets interrupted flag to
true . |
boolean |
interrupted()
Checks if transfer process was interrupted.
|
boolean |
isAutomaticVersionLoweringEnabled()
Returns automatic protocol version lowering flag.
|
boolean |
isConnected()
Tests whether the current service is connected to the remote host.
|
boolean |
isDirectory(java.lang.String remoteDirectory)
Checks if remote pathname denotes a directory.
|
boolean |
isPipelinedTransferEnabled() |
void |
makeDir(java.lang.String remoteDirectory)
Makes directory on SSH server.
|
void |
makeDirRecursive(java.lang.String remoteDirectory)
Makes directory on SSH server, creating subdirectories if necessary.
|
java.io.File |
makeLocalDir(java.lang.String localDirectory)
Creates local directory.
|
void |
mdelete(java.lang.String regex)
Deletes multiple files matching regular expression from SSH server's current directory.
|
void |
mdownload(java.util.Enumeration remoteFiles)
Downloads specified files in current working remote directory from SSH
server to local directory.
|
void |
mdownload(java.lang.String regex)
Downloads multiple files matching filter from SSH server's current
directory.
|
void |
mupload(java.util.Enumeration localFiles)
Uploads multiple files to SSH server.
|
void |
mupload(java.lang.String regex)
Uploads multiple files matching filter to SSH server's current directory.
|
void |
removeSftpListener(SftpListener listener)
Removes specified SSH event listener.
|
void |
renameFile(java.lang.String sourceRemoteFile,
java.lang.String destinationRemoteFile)
Renames remote file on SSH server.
|
void |
reset()
Resets the interrupted flag to
false . |
void |
resumeDownload(java.io.OutputStream out,
java.lang.String remoteFile,
long remoteFileOffset) |
java.io.File |
resumeDownload(java.lang.String remoteFile,
long remoteFileOffset)
Resumes download of file from SSH server.
|
java.io.File |
resumeDownload(java.lang.String localFile,
java.lang.String remoteFile,
long remoteFileOffset)
Resumes download of file from SSH server.
|
void |
resumeUpload(java.io.File localFile,
long localFileOffset)
Resumes upload of file to SSH server.
|
void |
resumeUpload(java.io.File localFile,
java.lang.String remoteFile,
long localFileOffset)
Resumes upload of file to SSH server.
|
void |
resumeUpload(java.io.InputStream in,
long length,
java.lang.String remoteFile,
long remoteFileOffset) |
void |
resumeUpload(java.lang.String localFile,
long localFileOffset)
Resumes upload of file to SSH server.
|
void |
resumeUpload(java.lang.String localFile,
java.lang.String remoteFile,
long localFileOffset)
Resumes upload of file to SSH server.
|
boolean |
sameChecksum(java.io.File localFile,
java.lang.String remoteFile) |
void |
setAscii()
Sets data transfer mode to ASCII.
|
void |
setAuto(boolean auto)
Sets data transfer mode to automatic detect
Any files with a base Content-Type value of text will be transferred
using ASCII, all other files will be transfered using binary.
|
void |
setAutomaticVersionLoweringEnabled(boolean value)
Sets automatic version lowering flag.
|
void |
setBinary()
Sets data transfer mode to binary.
|
void |
setBlockSize(int blockSize)
Deprecated.
see #setUploadBlockSize
|
void |
setConfiguration(SftpConfiguration value) |
void |
setDebug(boolean value)
Turns on/off debug log level.
|
void |
setDebugStream(java.io.PrintStream value)
Sets a debug stream.
|
void |
setDefaultDirectoryPermissions(int value) |
void |
setDefaultDirectoryPermissions(com.jscape.util.file.PosixFilePermissions value) |
void |
setDir(java.lang.String remoteDirectory)
Sets current directory on SSH server.
|
void |
setDirUp()
Sets current directory on SSH server to parent directory.
|
void |
setDownloadBlockSize(int blockSize)
Sets the transfer buffer size for download operation.
|
void |
setFileAccessTimestamp(java.lang.String remoteFile,
java.util.Date timestamp)
Sets file access time.
|
void |
setFileCreationTimestamp(java.lang.String remoteFile,
java.util.Date timestamp)
Sets file creation time.
|
void |
setFilePermissions(java.lang.String remoteFile,
int permissions)
Sets file permissions.
|
void |
setFileTimestamp(java.lang.String remoteFile,
java.util.Date timestamp)
Sets file modification time.
|
void |
setLineTerminator(java.lang.String value)
Sets destination line terminator used in ASCII file transfers.
|
void |
setLocalDir(java.io.File value)
Sets local directory to be used in session.
|
void |
setLogLevel(java.util.logging.Level level)
Sets current log level.
|
void |
setParameters(SshParameters value) |
void |
setPipelinedTransferEnabled(boolean value) |
void |
setPipelineWindowSize(int value)
Sets the window size (a number of request packets without response) in pipeline transfer mode.
|
void |
setProxyAuthentication(java.lang.String proxyUsername,
java.lang.String proxyPassword)
Sets the proxy authentication username and password to use with
proxy server.
|
void |
setProxyHost(java.lang.String proxyHostname,
int proxyPort)
Sets the proxy hostname and port for this connection.
|
void |
setProxyType(java.lang.String proxyType)
Sets the proxy type will be used for this FTP connection.
|
void |
setReceiveBufferSize(int value)
Sets the receive buffer size option of the sftp connection.
|
void |
setSendBufferSize(int value)
Sets the send buffer size option of the sftp connection.
|
void |
setTimeout(long timeout)
Deprecated.
use setParameters()
|
void |
setUploadBlockSize(int value)
Sets the transfer buffer size for upload operations.
|
void |
setVersion(int value)
Sets current target SFTP version.
|
void |
upload(byte[] data,
java.lang.String remoteFile)
Uploads file to SSH server where contents of file is not on disk but
in memory.
|
void |
upload(byte[] data,
java.lang.String remoteFile,
boolean shouldAppend)
Uploads file to SSH server where contents of file is not on disk but
in memory.
|
void |
upload(java.io.File localFile)
Uploads file to SSH server.
|
void |
upload(java.io.File localFile,
boolean append)
Uploads file to SSH server.
|
void |
upload(java.io.File localFile,
java.lang.String remoteFile)
Uploads file to SSH server.
|
void |
upload(java.io.File localFile,
java.lang.String remoteFile,
boolean shouldAppend)
Uploads file to SSH server.
|
void |
upload(java.io.InputStream input,
java.lang.String remoteFile)
Uploads file to SSH server.
|
void |
upload(java.io.InputStream in,
java.lang.String remoteFile,
boolean shouldAppend)
Uploads file to SSH server.
|
void |
upload(java.lang.String localFile)
Uploads file to SSH server.
|
void |
upload(java.lang.String localFile,
boolean shouldAppend)
Uploads file to SSH server.
|
void |
upload(java.lang.String tempFileExtension,
java.io.File localFile)
Uploads a file to SSH server.
|
void |
upload(java.lang.String localFile,
java.lang.String remoteFile)
Uploads file to SSH server.
|
void |
upload(java.lang.String localFile,
java.lang.String remoteFile,
boolean shouldAppend)
Uploads file to SSH server.
|
void |
uploadDir(java.io.File localDirectory)
Uploads local directory and contents recursively to SSH server.
|
void |
uploadDir(java.io.File localDirectory,
int retryAttempts)
Uploads local directory and contents.
|
void |
uploadDir(java.io.File localDirectory,
int retryAttempts,
int threadCount)
Uploads local directory and contents recursively to SSH server.
|
void |
uploadDir(java.io.File localDirectory,
int retryAttempts,
int retryInterval,
java.lang.String tempFileExtension)
Uploads local directory and contents.
|
void |
uploadDir(java.io.File localDirectory,
int retryAttempts,
int retryInterval,
java.lang.String tempFileExtension,
int threadCount)
Uploads local directory and contents.
|
void |
uploadDir(java.io.File localDirectory,
int retryAttempts,
java.lang.String tempFileExtension)
Uploads local directory and contents.
|
void |
uploadDir(java.io.File localDirectory,
int retryAttempts,
java.lang.String tempFileExtension,
int threadCount)
Uploads local directory and contents.
|
public static final int DEFAULT_VERSION
public static final int AUTO
public static final int ASCII
public static final int BINARY
public Sftp(SshParameters parameters, SftpConfiguration configuration, int version, java.io.File currentLocalDirectory, java.lang.String currentRemoteDirectory, int transferBufferSizeBytes, int pipelineWindowSize, java.util.logging.Logger logger)
parameters
- the connection parametersconfiguration
- the connection configurationcurrentLocalDirectory
- the local working directorypublic Sftp(SshParameters parameters, java.io.File currentLocalDirectory, SftpConfiguration configuration)
parameters
- a SSH parameterscurrentLocalDirectory
- a current local directoryconfiguration
- a SSH configurationpublic Sftp(SshParameters parameters, SftpConfiguration configuration)
parameters
- the connection parametersconfiguration
- the connection configurationpublic Sftp(SshParameters parameters, java.io.File currentLocalDirectory)
parameters
- the connection parameterscurrentLocalDirectory
- the local working directorypublic Sftp(SshParameters parameters)
parameters
- the connection parameterspublic static void clearProxySettings()
public SshParameters getSshParameters()
public SshParameters getParameters()
public void setParameters(SshParameters value)
public SftpConfiguration getConfiguration()
public void setConfiguration(SftpConfiguration value)
public int getVersion()
public void setVersion(int value)
value
- target SFTP version numberpublic boolean isAutomaticVersionLoweringEnabled()
true
if automatic protocol version lowering is enabled; false
otherwisepublic void setAutomaticVersionLoweringEnabled(boolean value)
value
- if true
the protocol version will be automatically lowered if server doesn't support current version.public void setProxyType(java.lang.String proxyType)
proxyType
- The proxy type. Values allowed: HTTP, SOCKS5public void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
proxyUsername
- the proxy usernameproxyPassword
- the proxy passwordpublic void setProxyHost(java.lang.String proxyHostname, int proxyPort)
proxyHostname
- the hostname or ip address of the proxy serverproxyPort
- the port of the proxy server to connect to@Deprecated public long getTimeout()
@Deprecated public void setTimeout(long timeout)
timeout
- the timeout in millisecondspublic int getMode()
public void setAscii()
public void setBinary()
public void setAuto(boolean auto)
auto
- true
to turn automatic detect on
false
to turn offpublic com.jscape.util.file.PosixFilePermissions getDefaultDirectoryPermissions()
public void setDefaultDirectoryPermissions(com.jscape.util.file.PosixFilePermissions value)
public void setDefaultDirectoryPermissions(int value)
public int getBlockSize()
@Deprecated public void setBlockSize(int blockSize)
blockSize
- the size in bytespublic int getUploadBlockSize()
public void setUploadBlockSize(int value)
value
- desired buffer sizepublic int getDownloadBlockSize()
public void setDownloadBlockSize(int blockSize)
blockSize
- desired buffer sizepublic void setSendBufferSize(int value)
value
- Send buffer size.public void setReceiveBufferSize(int value)
value
- Receive buffer size.public boolean isPipelinedTransferEnabled()
public void setPipelinedTransferEnabled(boolean value)
public int getPipelineWindowSize()
public void setPipelineWindowSize(int value)
value
- a window sizepublic void setLineTerminator(java.lang.String value)
null
. If null
, SFTP server must support ASCII transfers
and it will be the responsibility of server to perform conversion. Otherwise,
client will perform conversion from local system line terminator to specified
destination line terminator during transfer.value
- line terminatorpublic java.lang.String getLineTerminator()
null
. If null
, SFTP server must support ASCII transfers
and it will be the responsibility of server to perform conversion. Otherwise,
client will perform conversion from local system line terminator to specified
destination line terminator during transfer.public java.util.logging.Level getLogLevel()
public void setLogLevel(java.util.logging.Level level)
level
- new log levelpublic boolean getDebug()
true
if debug mode is turned onpublic void setDebug(boolean value)
value
- if true
debug level will bw turned onpublic void disableFileAccessLogging()
public void enableFileAccessLogging()
public java.io.PrintStream getDebugStream()
public void setDebugStream(java.io.PrintStream value)
value
- debug streampublic void addSftpListener(SftpListener listener)
listener
- the listener to addpublic void removeSftpListener(SftpListener listener)
listener
- the listener to removepublic SshHostKeys getHostKeys()
public java.io.File getLocalDir()
public void setLocalDir(java.io.File value)
value
- the local directorypublic java.util.Enumeration getLocalDirListing(java.lang.String regex)
regex
- Regular expression used to obtain the file listEnumeration
of File
public java.util.Enumeration getLocalDirListing()
Enumeration
of File
public java.io.File makeLocalDir(java.lang.String localDirectory) throws SftpException
localDirectory
- name of directorySftpException
public Sftp connect() throws SftpException
SftpException
- if an I/O or SSH error occurs.SshParameters
public void disconnect()
public void close()
close
in interface java.lang.AutoCloseable
public boolean isConnected()
true
if the service is connected;
false
otherwisepublic java.lang.String getDir()
public void setDir(java.lang.String remoteDirectory) throws SftpException
remoteDirectory
- the remote directorySftpException
- if an I/O or SSH error occurs.public void setDirUp() throws SftpException
SftpException
- If an error occurspublic java.util.Enumeration getDirListing(java.lang.String remoteDirectory, java.lang.String regex) throws SftpException
SftpException
public java.util.Enumeration getDirListing(java.lang.String regex) throws SftpException
regex
- Regular expression used to obtain the file listSftpException
- If an error occurs.public java.util.Enumeration getDirListing() throws SftpException
Enumeration
of SftpFile
objectsSftpException
- if an I/O or SSH error occurs.getDirListingAsString()
public java.lang.String getDirListingAsString(java.lang.String regex) throws SftpException
regex
- regular expression used to obtain the file listSftpException
- if an I/O or SSH error occurs.public java.lang.String getDirListingAsString() throws SftpException
SftpException
- if an I/O or SSH error occurs.public java.util.Enumeration getNameListing(java.lang.String regex) throws SftpException
regex
- regular expression used to obtain the file listEnumeration
of String
containing filenamesSftpException
- if an I/O or SSH error occurs.public java.util.Enumeration getNameListing() throws SftpException
Enumeration
of String
where each item represents a file
or directory nameSftpException
- if an I/O or SSH error occurs.public void makeDir(java.lang.String remoteDirectory) throws SftpException
remoteDirectory
- name of directory to makeSftpException
- if an I/O or SSH error occurs.public void makeDirRecursive(java.lang.String remoteDirectory) throws SftpException
remoteDirectory
- full path of directory to makeSftpException
- if an I/O or SSH error occurspublic void deleteDir(java.lang.String remoteDirectory) throws SftpException
remoteDirectory
- the directory to deleteSftpException
- if an I/O or SSH error occurs.public void deleteDir(java.lang.String remoteDirectory, boolean recursive) throws SftpException
remoteDirectory
- the directory to delete.recursive
- true
if directory contents should be deleted recursivelySftpException
- if an I/O or SSH error occurs.public java.util.Vector getRemoteFileList(java.lang.String remoteDirectory) throws SftpException
SftpException
- If a IO error occurspublic int getRecursiveDirectoryFileCount(java.lang.String remoteDirectory) throws SftpException
remoteDirectory
- - the remote directory nameSftpException
public long getRecursiveDirectorySize(java.lang.String remoteDirectory) throws SftpException
remoteDirectory
- - the remote directory nameSftpException
public java.lang.String getRealPath(java.lang.String remotePath) throws SftpException
remotePath
- path to resolveSftpException
- if an error occurspublic boolean exists(java.lang.String remotePath) throws SftpException
remotePath
- path to checktrue
if path is valid;
false
otherwiseSftpException
- if an error occurspublic boolean isDirectory(java.lang.String remoteDirectory) throws SftpException
remoteDirectory
- remote pathnametrue
if remote pathname denotes a directory; false
otherwiseSftpException
- if an I/O or SSH error occurs.public com.jscape.util.file.UnixFileType getType(java.lang.String remotePath) throws SftpException
remotePath
- a remote pathSftpException
- if an error occurspublic java.lang.String getSymbolicLinkTargetPath(java.lang.String remoteFile) throws SftpException
remoteFile
- the remote link fileSftpException
- if an error occurspublic long getFilesize(java.lang.String remoteFile) throws SftpException
remoteFile
- the remote fileSftpException
- if an I/O or SSH error occurs.public java.util.Date getFileCreationTimestamp(java.lang.String remoteFile) throws SftpException
remoteFile
- the remote filenameSftpException
- if an I/O or SSH error occurs.public void setFileCreationTimestamp(java.lang.String remoteFile, java.util.Date timestamp) throws SftpException
remoteFile
- the remote file nametimestamp
- the file creation timeSftpException
- if an I/O or SSH error occurs.public java.util.Date getFileAccessTimestamp(java.lang.String remoteFile) throws SftpException
remoteFile
- the remote filenameSftpException
- if an I/O or SSH error occurs.public void setFileAccessTimestamp(java.lang.String remoteFile, java.util.Date timestamp) throws SftpException
remoteFile
- the remote file nametimestamp
- the file access timeSftpException
- if an I/O or SSH error occurs.public java.util.Date getFileTimestamp(java.lang.String remoteFile) throws SftpException
remoteFile
- the remote filenameSftpException
- if an I/O or SSH error occurs.public void setFileTimestamp(java.lang.String remoteFile, java.util.Date timestamp) throws SftpException
remoteFile
- the remote file nametimestamp
- the file modification timeSftpException
- if an I/O or SSH error occurs.public int getFilePermissions(java.lang.String remoteFile) throws SftpException
remoteFile
- the remote filenameSftpException
- if an I/O or SSH error occurs.public void setFilePermissions(java.lang.String remoteFile, int permissions) throws SftpException
remoteFile
- remote file namepermissions
- UNIX chmod file permissionsSftpException
- if an I/O or SSH error occurs.public boolean sameChecksum(java.io.File localFile, java.lang.String remoteFile) throws SftpException
SftpException
public void createSymbolicLink(java.lang.String remoteLinkFile, java.lang.String remoteTargetFile) throws SftpException
remoteLinkFile
- a link fileremoteTargetFile
- a link target fileSftpException
- if an error occurspublic void renameFile(java.lang.String sourceRemoteFile, java.lang.String destinationRemoteFile) throws SftpException
sourceRemoteFile
- name of file to renamedestinationRemoteFile
- new name of fileSftpException
- if an I/O or SSH error occurs.public void deleteFile(java.lang.String remoteFile) throws SftpException
remoteFile
- the file to deleteSftpException
- if an I/O or SSH error occurs.public void mdelete(java.lang.String regex) throws SftpException
regex
- the regular expression to useSftpException
- if an I/O or SSH error occurs.public void download(java.io.OutputStream out, java.lang.String remoteFile, long remoteFileOffset) throws SftpException
OutputStream
.out
- the OutputStream
to write file toremoteFile
- the remote file to downloadremoteFileOffset
- the offset into the remote file in bytesSftpException
- if an I/O or SSH error occurs.public void download(java.io.OutputStream out, java.lang.String remoteFile) throws SftpException
OutputStream
.out
- the OutputStream
to write file toremoteFile
- the remote file to downloadSftpException
- if an I/O or SSH error occurs.public java.io.File download(java.lang.String localFile, java.lang.String remoteFile) throws SftpException
localFile
- the local file to downloadremoteFile
- the remote file to downloadSftpException
- if an I/O or SSH error occurs.public java.io.File download(java.lang.String remoteFile) throws SftpException
remoteFile
- the remote file to downloadSftpException
- if an I/O or SSH error occurs.public java.io.File resumeDownload(java.lang.String localFile, java.lang.String remoteFile, long remoteFileOffset) throws SftpException
localFile
- local file nameremoteFile
- the file to downloadremoteFileOffset
- file offset in bytesSftpException
- if an I/O or SSH error occurs.setLocalDir(File)
public void resumeDownload(java.io.OutputStream out, java.lang.String remoteFile, long remoteFileOffset) throws SftpException
SftpException
public java.io.File resumeDownload(java.lang.String remoteFile, long remoteFileOffset) throws SftpException
remoteFile
- the file to downloadremoteFileOffset
- file offset in bytesSftpException
- if an I/O or SSH error occurs.setLocalDir(File)
public void mdownload(java.util.Enumeration remoteFiles) throws SftpException
downloadDir(String)
method.
Downloads are stored relative to current local directory.remoteFiles
- filenames of files to downloadSftpException
- if an I/O or SSH error occurs.downloadDir(String)
,
setLocalDir(File)
public void mdownload(java.lang.String regex) throws SftpException
downloadDir
method.regex
- the filter to useSftpException
- if an I/O or SSH error occurs.downloadDir(java.lang.String, int, int, int)
,
setLocalDir(File)
public void downloadDir(java.lang.String remoteDirectory, int retryAttempts, int retryInterval, int threadCount) throws SftpException
remoteDirectory
- the directory to downloadretryAttempts
- The retry limit numberretryInterval
- the retry interval in secondsthreadCount
- the number of threads.SftpException
- if an I/O or SSH error occurs.setLocalDir(java.io.File)
public void downloadDir(java.lang.String remoteDirectory, int retryAttempts, int retryInterval) throws SftpException
remoteDirectory
- the directory to downloadretryAttempts
- The retry limit numberretryInterval
- the retry interval in secondsSftpException
- if an I/O or SSH error occurs.setLocalDir(java.io.File)
public void downloadDir(java.lang.String remoteDirectory, int retryAttempts) throws SftpException
remoteDirectory
- the directory to downloadretryAttempts
- The retry limit numberSftpException
- if an I/O or SSH error occurs.setLocalDir(java.io.File)
public void downloadDir(java.lang.String remoteDirectory) throws SftpException
remoteDirectory
- the directory to downloadSftpException
- if an I/O or SSH error occurs.setLocalDir(File)
public void upload(java.io.InputStream in, java.lang.String remoteFile, boolean shouldAppend) throws SftpException
in
- the input stream to read fromremoteFile
- the filename to store file as on SSH servershouldAppend
- true
to append to remote file, false
otherwiseSftpException
- if an I/O or SSH error occurspublic void upload(java.io.InputStream input, java.lang.String remoteFile) throws SftpException
input
- the input stream to read fromremoteFile
- the filename to store file as on SSH serverSftpException
- if an I/O or SSH error occurspublic void upload(byte[] data, java.lang.String remoteFile, boolean shouldAppend) throws SftpException
data
- the raw contents of the file to uploadremoteFile
- the filename to store file as on SSH servershouldAppend
- true
to appending to remote file
on SSH server; false
otherwiseSftpException
- if an I/O or SSH error occurs.public void upload(byte[] data, java.lang.String remoteFile) throws SftpException
data
- the raw contents of the file to uploadremoteFile
- the filename to store file as on SSH serverSftpException
- if an I/O or SSH error occurs.public void upload(java.io.File localFile, java.lang.String remoteFile, boolean shouldAppend) throws SftpException
localFile
- the local file to uploadremoteFile
- the destination of uploadshouldAppend
- true
to appending to remote file
on SSH server, false
otherwiseSftpException
- if an I/O or SSH error occurs.public void upload(java.io.File localFile, java.lang.String remoteFile) throws SftpException
localFile
is a directory then directory and entire contents
are uploaded.localFile
- the local file to uploadremoteFile
- the destination of uploadSftpException
- if an I/O or SSH error occurs.public void upload(java.io.File localFile, boolean append) throws SftpException
localFile
- the local file to uploadappend
- true
to appending to remote file
on SSH server, false
otherwiseSftpException
- if an I/O or SSH error occurs.public void upload(java.io.File localFile) throws SftpException
localFile
is a directory then directory and entire contents
are uploaded.localFile
- the local file to uploadSftpException
- if an I/O or SSH error occurs.public void upload(java.lang.String tempFileExtension, java.io.File localFile) throws SftpException
tempFileExtension
- The extension will be usedlocalFile
- The local file to uploadSftpException
- if an I/O or SSH related error occurspublic void upload(java.lang.String localFile, java.lang.String remoteFile, boolean shouldAppend) throws SftpException
localFile
- the local file to uploadremoteFile
- the destination filename of uploadshouldAppend
- true
to appending to remote file
on SSH server, false
otherwiseSftpException
- if an I/O or SSH error occurs.setLocalDir(File)
public void upload(java.lang.String localFile, java.lang.String remoteFile) throws SftpException
localFile
- the local file to uploadremoteFile
- the destination filename of uploadSftpException
- if an I/O or SSH error occurs.setLocalDir(File)
public void upload(java.lang.String localFile, boolean shouldAppend) throws SftpException
localFile
- the local file to uploadshouldAppend
- true
to appending to remote file
on SSH server, false
otherwiseSftpException
- if an I/O or SSH error occurs.public void upload(java.lang.String localFile) throws SftpException
localFile
- the local file to uploadSftpException
- if an I/O or SSH error occurs.setLocalDir(File)
public void resumeUpload(java.io.File localFile, java.lang.String remoteFile, long localFileOffset) throws SftpException
localFile
- the local file to uploadremoteFile
- the destination remote filelocalFileOffset
- the local file offset in bytesSftpException
- if an I/O or SSH related error occurspublic void resumeUpload(java.io.InputStream in, long length, java.lang.String remoteFile, long remoteFileOffset) throws SftpException
SftpException
public void resumeUpload(java.io.File localFile, long localFileOffset) throws SftpException
localFile
- the local file to uploadlocalFileOffset
- file offset in bytesSftpException
- if an I/O or SSH error occurs.public void resumeUpload(java.lang.String localFile, java.lang.String remoteFile, long localFileOffset) throws SftpException
localFile
- the local file to uploadremoteFile
- the remote destination filelocalFileOffset
- the local file offset in bytesSftpException
- if an I/O or SSH error occurssetLocalDir(File)
public void resumeUpload(java.lang.String localFile, long localFileOffset) throws SftpException
localFile
- the local file to uploadlocalFileOffset
- file offset in bytesSftpException
- if an I/O or SSH error occurs.setLocalDir(File)
public void mupload(java.util.Enumeration localFiles) throws SftpException
localFiles
- filenames of files to uploadSftpException
- if an I/O or SSH error occurs.public void mupload(java.lang.String regex) throws SftpException
regex
- the regular expression to useSftpException
- if an I/O or SSH error occurs.public void uploadDir(java.io.File localDirectory, int retryAttempts, int retryInterval, java.lang.String tempFileExtension, int threadCount) throws SftpException
localDirectory
- the directory to uploadretryAttempts
- number of times to retry if upload failsretryInterval
- retry interval in secondstempFileExtension
- the temporary extension which will be used to upload the files or null
for default extensionthreadCount
- the upload thread count.SftpException
- if an I/O or SSH error occurs.public void uploadDir(java.io.File localDirectory, int retryAttempts, int retryInterval, java.lang.String tempFileExtension) throws SftpException
localDirectory
- the directory to uploadretryAttempts
- number of times to retry if upload failsretryInterval
- retry interval in secondstempFileExtension
- the temporary extension which will be used to upload the files or null
for default extensionSftpException
- if an I/O or SSH error occurs.public void uploadDir(java.io.File localDirectory, int retryAttempts, java.lang.String tempFileExtension, int threadCount) throws SftpException
localDirectory
- the directory to uploadretryAttempts
- number of times to retry if upload failstempFileExtension
- the temporary extension which will be used to upload the files or null
for default extensionthreadCount
- the number of new threads to spawn for upload.SftpException
- if an I/O or SSH error occurs.public void uploadDir(java.io.File localDirectory, int retryAttempts, java.lang.String tempFileExtension) throws SftpException
localDirectory
- the directory to uploadretryAttempts
- number of times to retry if upload failstempFileExtension
- the temporary extension which will be used to upload the files or null
for default extensionSftpException
- if an I/O or SSH error occurs.public void uploadDir(java.io.File localDirectory, int retryAttempts, int threadCount) throws SftpException
localDirectory
- the directory to uploadthreadCount
- the number of threads to spawn for uploadretryAttempts
- number of times to retry if upload failsSftpException
- if an I/O or SSH error occurs.public void uploadDir(java.io.File localDirectory, int retryAttempts) throws SftpException
localDirectory
- the directory to uploadretryAttempts
- number of times to retry if upload failsSftpException
- if an I/O or SSH error occurs.public void uploadDir(java.io.File localDirectory) throws SftpException
localDirectory
- the directory to uploadSftpException
- if an I/O or SSH error occurs.public java.io.InputStream getInputStream(java.lang.String remoteFile, long remoteFileOffset) throws SftpException
SftpException
public java.io.OutputStream getOutputStream(java.lang.String remoteFile, long remoteFileOffset, boolean append) throws SftpException
SftpException
public void interrupt()
true
.
After invoking this method you must reset the interrupted flag to false
before transferring any files.reset()
public boolean interrupted()
true
if transfer process was interrupted;
false
otherwisepublic void reset()
false
.
This method should be invoked if you have interrupted a transfer
using the Sftp#interrupt
method and wish to resume transfering files.interrupt()
public void abortDownloadThreads()
public void abortDownloadThread(java.lang.String remoteFile)
remoteFile
- public void abortUploadThreads()
public void abortUploadThread(java.lang.String remoteFile)
public Sftp copy()
Copyright © JSCAPE LLC. 1999-2023. All Rights Reserved