Class SftpClientTask
- All Implemented Interfaces:
RequestFuture,Runnable
SftpRunnable) should be passed in the constructor.-
Nested Class Summary
Nested classes/interfaces inherited from class com.sshtools.client.tasks.Task
Task.TaskRunnable<T> -
Field Summary
Fields inherited from class com.sshtools.common.ssh.ConnectionAwareTask
con, lastError -
Constructor Summary
ConstructorsConstructorDescriptionSftpClientTask(SshClient ssh) Deprecated, for removal: This API element is subject to removal in a future version.SftpClientTask(SshConnection con, Task.TaskRunnable<SftpClientTask> runnable) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCustomRoot(String rootPath) Deprecated, for removal: This API element is subject to removal in a future version.voidChanges the working directory on the remote server, or the user's default directory ifnullor any empty string is provided as the directory path.voidcdup()Change the working directory to the parent directoryvoidSets the group ID for the file or directory.voidDeprecated.voidchmod(PosixPermissions permissions, String path) Changes the access permissions or modes of the specified file or directory.voidSets the user ID to owner for the file or directory.protected voiddoSftp()Deprecated, for removal: This API element is subject to removal in a future version.protected final voiddoTask()voidexit()Close the SFTP client.static StringformatLongname(SftpFile file) Format a String with the details of the file.static StringformatLongname(SftpFileAttributes attrs, String filename) Format a String with the details of the file.Download the remote file to the local computerDownload the remote file to the local computerget(String path, FileTransferProgress progress) Download the remote file to the local computer.get(String path, FileTransferProgress progress, boolean resume) Download the remote file to the local computer.get(String remote, OutputStream local) Download the remote file into an OutputStream.get(String remote, OutputStream local, long position) Download the remote file into an OutputStream.get(String remote, OutputStream local, FileTransferProgress progress) Download the remote file writing it to the specifiedOutputStream.get(String remote, OutputStream local, FileTransferProgress progress, long position) Download the remote file writing it to the specifiedOutputStream.Download the remote file into the local file.Download the remote file into the local file.get(String remote, String local, FileTransferProgress progress) Download the remote file to the local computer.get(String remote, String local, FileTransferProgress progress, boolean resume) Download the remote file to the local computer.getAbsolutePath(String path) Get the absolute path for a file.Get the default directory (or HOME directory)intgetEOL(byte[] nl) intSftpFile[]Download the remote files to the local computerSftpFile[]Download the remote files to the local computerSftpFile[]getFiles(String remote, FileTransferProgress progress) Download the remote files to the local computer.SftpFile[]getFiles(String remote, FileTransferProgress progress, boolean resume) Download the remote files to the local computer.SftpFile[]Download the remote files into the local file.SftpFile[]Download the remote files into the local file.SftpFile[]getFiles(String remote, String local, FileTransferProgress progress, boolean resume) Download the remote file to the local computer.getInputStream(String remotefile) Create an InputStream for reading a remote file.getInputStream(String remotefile, long position) Create an InputStream for reading a remote file.getOutputStream(String remotefile) Create an OutputStream for writing to a remote file.getRemoteDirectory(String remotedir, String localdir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress) Copy the contents of a remote directory to a local directoryintReturns the instance of the AbstractSftpChannel used by this classgetSymbolicLinkTarget(String linkpath) Get the target path of a symbolic link.intbooleanisClosed()Returns the state of the SFTP client.booleanDetermine whether the file object is pointing to a symbolic link that is pointing to a directory.voidChanges the local working directory.lpwd()Returns the absolute path to the local working directory.SftpFile[]ls()List the contents of the current remote working directory.SftpFile[]List the contents remote directory.SftpFile[]matchRemoteFiles(String remote) Called by getFileMatches() to do regular expression pattern matching on the files in 'remote''s parent directory.voidCreates a new directory on the remote server.voidCreate a directory or set of directories.openDirectory(String path) voidput(InputStream in, String remote) Upload the contents of an InputStream to the remote computer.voidput(InputStream in, String remote, long position) Upload the contents of an InputStream to the remote computer.voidput(InputStream in, String remote, FileTransferProgress progress) Upload a file to the remote computer reading from the specifiedInputStream.voidput(InputStream in, String remote, FileTransferProgress progress, long position) Deprecated.voidput(InputStream in, String remote, FileTransferProgress progress, long position, long length) voidUpload a file to the remote computervoidUpload a file to the remote computervoidput(String local, FileTransferProgress progress) Upload a file to the remote computer.voidput(String local, FileTransferProgress progress, boolean resume) Upload a file to the remote computer.voidUpload a file to the remote computervoidUpload a file to the remote computervoidput(String local, String remote, FileTransferProgress progress) Upload a file to the remote computer.voidput(String local, String remote, FileTransferProgress progress, boolean resume) Upload a file to the remote computer.voidUpload the contents of an InputStream to the remote computer.voidUpload files to the remote computervoidputFiles(String local, FileTransferProgress progress) Upload files to the remote computervoidputFiles(String local, FileTransferProgress progress, boolean resume) Upload files to the remote computervoidUpload files to the remote computervoidUpload files to the remote computervoidputFiles(String local, String remote, FileTransferProgress progress) Upload files to the remote computer.voidputFiles(String local, String remote, FileTransferProgress progress, boolean resume) make local copies of some of the variables, then call putfilematches, which calls "put" on each file that matches the regexp local.putLocalDirectory(String localdir, String remotedir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress) Copy the contents of a local directory into a remote directory.pwd()Returns the absolute path name of the current remote working directory.voidquit()Close the SFTP client.readDirectory(SftpHandle dir) voidremoveCustomRoot(String rootPath) Deprecated, for removal: This API element is subject to removal in a future version.voidRename a file on the remote computer.voidRemove a file or directory from the remote computer.voidRemove a file or directory on the remote computer with options to force deletion of existing files and recursion.voidsetBlockSize(int blocksize) Deprecated, for removal: This API element is subject to removal in a future version.voidsetBufferSize(int buffersize) Set the size of the buffer which is used to read from the local file system.voidsetForceRemoteEOL(boolean forceRemoteEOL) Override automatic detection of the remote EOL (any SFTP version).voidsetLocalEOL(int eolMode) Override the default local system EOL for text mode files.voidsetMaxAsyncRequests(int asyncRequests) Deprecated, for removal: This API element is subject to removal in a future version.voidsetRegularExpressionSyntax(int syntax) sets the type of regular expression matching to perform on gets and putsvoidsetRemoteEOL(int eolMode) When connected to servers running SFTP version 3 (or less) the remote EOL type needs to be explicitly set because there is no reliable way for the client to determine the type of EOL for text files.voidsetTransferMode(int transferMode) Sets the transfer mode for current operations.Returns the attributes of the file from the remote computer.Returns the attributes of the link from the remote computer.voidCreate a symbolic link on the remote computer.intumask(int umask) Sets the umask used by this client.voidSets the umask for this client.
booleanverifyFiles(String localFile, String remoteFile) Verify a local and remote file.booleanverifyFiles(String localFile, String remoteFile, long offset, long length) Verify a local and remote file.Methods inherited from class com.sshtools.client.tasks.Task
ofRunnableMethods inherited from class com.sshtools.common.ssh.ConnectionAwareTask
getLastError, runMethods inherited from class com.sshtools.common.ssh.AbstractRequestFuture
addFutureListener, done, isDone, isSuccess, waitFor, waitForeverMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.sshtools.common.ssh.RequestFuture
isDoneAndSuccess
-
Constructor Details
-
SftpClientTask
Deprecated, for removal: This API element is subject to removal in a future version. -
SftpClientTask
-
SftpClientTask
-
-
Method Details
-
doTask
- Specified by:
doTaskin classConnectionAwareTask- Throws:
Throwable
-
doSftp
Deprecated, for removal: This API element is subject to removal in a future version. -
setBlockSize
Deprecated, for removal: This API element is subject to removal in a future version.Sets the block size used when transferring files, defaults to the optimized setting of 32768. You should not increase this value as the remote server may not be able to support higher blocksizes.- Parameters:
blocksize-
-
getSubsystemChannel
Returns the instance of the AbstractSftpChannel used by this class- Returns:
- the AbstractSftpChannel instance
-
setTransferMode
public void setTransferMode(int transferMode) Sets the transfer mode for current operations. The valid modes are:
#MODE_BINARY- Files are transferred in binary mode and no processing of text files is performed (default mode).
#MODE_TEXT- For servers supporting version 4+ of the SFTP protocol files are transferred in text mode. For earlier protocol versions the files are transfered in binary mode but the client performs processing of text; if files are written to the remote server the client ensures that the line endings conform to the remote EOL mode set usingsetRemoteEOL(int). For files retrieved from the server the EOL policy is based upon System policy as defined by the "line.seperator" system property.- Parameters:
transferMode- int
-
setRemoteEOL
public void setRemoteEOL(int eolMode) When connected to servers running SFTP version 3 (or less) the remote EOL type needs to be explicitly set because there is no reliable way for the client to determine the type of EOL for text files. In versions 4+ a mechanism is provided and this setting is overridden.
Valid values for this method are
EOL_CRLF(default),EOL_CR, andEOL_LF.- Parameters:
eolMode- int
-
setLocalEOL
public void setLocalEOL(int eolMode) Override the default local system EOL for text mode files.
Valid values for this method are
EOL_CRLF(default),EOL_CR, andEOL_LF.- Parameters:
eolMode- int
-
setForceRemoteEOL
public void setForceRemoteEOL(boolean forceRemoteEOL) Override automatic detection of the remote EOL (any SFTP version). USE WITH CAUTION.- Parameters:
forceRemoteEOL-
-
getTransferMode
public int getTransferMode()- Returns:
- int
-
setBufferSize
public void setBufferSize(int buffersize) Set the size of the buffer which is used to read from the local file system. This setting is used to optimize the writing of files by allowing for a large chunk of data to be read in one operation from a local file. The previous version simply read each block of data before sending however this decreased performance, this version now reads the file into a temporary buffer in order to reduce the number of local filesystem reads. This increases performance and so this setting should be set to the highest value possible. The default setting is negative which means the entire file will be read into a temporary buffer.- Parameters:
buffersize-
-
setMaxAsyncRequests
Deprecated, for removal: This API element is subject to removal in a future version.Set the maximum number of asynchronous requests that are outstanding at any one time. This setting is used to optimize the reading and writing of files to/from the remote file system when using the get and put methods. The default for this setting is 100.- Parameters:
asyncRequests-
-
umask
public int umask(int umask) Sets the umask used by this client.To give yourself full permissions for both files and directories and prevent the group and other users from having access: umask(077); This subtracts 077 from the system defaults for files and directories 666 and 777. Giving a default access permissions for your files of 600 (rw-------) and for directories of 700 (rwx------). To give all access permissions to the group and allow other users read and execute permission: umask(002); This subtracts 002 from the system defaults to give a default access permission for your files of 664 (rw-rw-r--) and for your directories of 775 (rwxrwxr-x). To give the group and other users all access except write access: umask(022); This subtracts 022 from the system defaults to give a default access permission for your files of 644 (rw-r--r--) and for your directories of 755 (rwxr-xr-x).
- Parameters:
umask-- Returns:
- the previous umask value
-
openFile
- Throws:
SftpStatusExceptionSshException
-
openFile
- Throws:
SftpStatusExceptionSshException
-
openDirectory
- Throws:
SftpStatusExceptionSshException
-
readDirectory
- Throws:
SftpStatusExceptionSshException
-
cd
Changes the working directory on the remote server, or the user's default directory if
nullor any empty string is provided as the directory path. The user's default directory is typically their home directory but is dependent upon server implementation.- Parameters:
dir- the new working directory- Throws:
IOException- if an IO error occurs or the file does not existSftpStatusExceptionSshException
-
getDefaultDirectory
Get the default directory (or HOME directory)
- Returns:
- String
- Throws:
SftpStatusExceptionSshException
-
cdup
Change the working directory to the parent directory- Throws:
SftpStatusExceptionSshException
-
addCustomRoot
Deprecated, for removal: This API element is subject to removal in a future version.Add a custom file system root path such as "flash:"- Parameters:
rootPath-
-
removeCustomRoot
Deprecated, for removal: This API element is subject to removal in a future version.Remove a custom file system root path such as "flash:"- Parameters:
rootPath-
-
mkdir
Creates a new directory on the remote server. This method will throw an exception if the directory already exists. To create directories and disregard any errors use the
mkdirsmethod.- Parameters:
dir- the name of the new directory- Throws:
SftpStatusExceptionSshException
-
mkdirs
Create a directory or set of directories. This method will not fail even if the directories exist. It is advisable to test whether the directory exists before attempting an operation by using stat to return the directories attributes.
- Parameters:
dir- the path of directories to create.- Throws:
SftpStatusExceptionSshException
-
isDirectoryOrLinkedDirectory
Determine whether the file object is pointing to a symbolic link that is pointing to a directory.- Returns:
- boolean
- Throws:
SftpStatusExceptionSshException
-
pwd
Returns the absolute path name of the current remote working directory.
- Returns:
- the absolute path of the remote working directory.
- Throws:
SshExceptionSftpStatusException
-
ls
List the contents of the current remote working directory.
Returns a list of SftpFile instances for the current working directory.
- Returns:
- a list of SftpFile for the current working directory
- Throws:
SftpStatusExceptionSshException
-
ls
List the contents remote directory.
Returns a list of SftpFile instances for the remote directory.
- Parameters:
path- the path on the remote server to list- Returns:
- a list of SftpFile for the remote directory
- Throws:
SftpStatusExceptionSshException
-
lcd
Changes the local working directory.
- Parameters:
path- the path to the new working directory- Throws:
SftpStatusExceptionPermissionDeniedExceptionIOException
-
lpwd
Returns the absolute path to the local working directory.
- Returns:
- the absolute path of the local working directory.
- Throws:
PermissionDeniedExceptionIOException
-
get
public SftpFileAttributes get(String path, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote file to the local computer.
- Parameters:
path- the path to the remote fileprogress-- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
get
public SftpFileAttributes get(String path, FileTransferProgress progress, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote file to the local computer.
- Parameters:
path- the path to the remote fileprogress-resume- attempt to resume a interrupted download- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
get
public SftpFileAttributes get(String path, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote file to the local computer
- Parameters:
path- the path to the remote fileresume- attempt to resume an interrupted download- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
get
public SftpFileAttributes get(String path) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote file to the local computer
- Parameters:
path- the path to the remote file- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
getSymbolicLinkTarget
Get the target path of a symbolic link.- Parameters:
linkpath-- Returns:
- String
- Throws:
SshException- if the remote SFTP version is < 3 an exception is thrown as this feature is not supported by previous versions of the protocol.SftpStatusException
-
get
public SftpFileAttributes get(String remote, String local, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote file to the local computer. If the paths provided are not absolute the current working directory is used.
- Parameters:
remote- the path/name of the remote filelocal- the path/name to place the file on the local computerprogress-- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
get
public SftpFileAttributes get(String remote, String local, FileTransferProgress progress, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote file to the local computer. If the paths provided are not absolute the current working directory is used.
- Parameters:
remote- the path/name of the remote filelocal- the path/name to place the file on the local computerprogress-resume- attempt to resume an interrupted download- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
getRemoteNewline
- Throws:
SftpStatusException
-
getRemoteEOL
- Throws:
SftpStatusException
-
getEOL
- Throws:
SftpStatusException
-
getEOL
- Throws:
SftpStatusException
-
get
public SftpFileAttributes get(String remote, String local, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote file into the local file.- Parameters:
remote-local-resume- attempt to resume an interrupted download- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
get
public SftpFileAttributes get(String remote, String local) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote file into the local file.- Parameters:
remote-local-- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
get
public SftpFileAttributes get(String remote, OutputStream local, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException Download the remote file writing it to the specified
OutputStream. The OutputStream is closed by this method even if the operation fails.- Parameters:
remote- the path/name of the remote filelocal- the OutputStream to writeprogress-- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledException
-
setRegularExpressionSyntax
public void setRegularExpressionSyntax(int syntax) sets the type of regular expression matching to perform on gets and puts- Parameters:
syntax- , NoSyntax for no regular expression matching, GlobSyntax for GlobSyntax, Perl5Syntax for Perl5Syntax
-
matchRemoteFiles
Called by getFileMatches() to do regular expression pattern matching on the files in 'remote''s parent directory.- Parameters:
remote-- Returns:
- SftpFile[]
- Throws:
SftpStatusExceptionSshException
-
get
public SftpFileAttributes get(String remote, OutputStream local, FileTransferProgress progress, long position) throws SftpStatusException, SshException, TransferCancelledException Download the remote file writing it to the specified
OutputStream. The OutputStream is closed by this method even if the operation fails.- Parameters:
remote- the path/name of the remote filelocal- the OutputStream to writeprogress-position- the position within the file to start reading from- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledException
-
getInputStream
public InputStream getInputStream(String remotefile, long position) throws SftpStatusException, SshException Create an InputStream for reading a remote file.- Parameters:
remotefile-position-- Returns:
- InputStream
- Throws:
SftpStatusExceptionSshException
-
getInputStream
Create an InputStream for reading a remote file.- Parameters:
remotefile-- Returns:
- InputStream
- Throws:
SftpStatusExceptionSshException
-
get
public SftpFileAttributes get(String remote, OutputStream local, long position) throws SftpStatusException, SshException, TransferCancelledException Download the remote file into an OutputStream.- Parameters:
remote-local-position- the position from which to start reading the remote file- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledException
-
get
public SftpFileAttributes get(String remote, OutputStream local) throws SftpStatusException, SshException, TransferCancelledException Download the remote file into an OutputStream.- Parameters:
remote-local-- Returns:
- the downloaded file's attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledException
-
isClosed
public boolean isClosed()Returns the state of the SFTP client. The client is closed if the underlying session channel is closed. Invoking the
quitmethod of this object will close the underlying session channel.- Returns:
- true if the client is still connected, otherwise false
-
put
public void put(String local, FileTransferProgress progress, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload a file to the remote computer.
- Parameters:
local- the path/name of the local fileprogress-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
put
public void put(String local, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload a file to the remote computer.
- Parameters:
local- the path/name of the local fileprogress-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
put
public void put(String local) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload a file to the remote computer- Parameters:
local-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
put
public void put(String local, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload a file to the remote computer- Parameters:
local-resume- attempt to resume after an interrupted transfer- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
put
public void put(String local, String remote, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload a file to the remote computer. If the paths provided are not absolute the current working directory is used.
- Parameters:
local- the path/name of the local fileremote- the path/name of the destination fileprogress-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
put
public void put(String local, String remote, FileTransferProgress progress, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload a file to the remote computer. If the paths provided are not absolute the current working directory is used.
- Parameters:
local- the path/name of the local fileremote- the path/name of the destination fileprogress-resume- attempt to resume after an interrupted transfer- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
put
public void put(String local, String remote, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload a file to the remote computer- Parameters:
local-remote-resume- attempt to resume after an interrupted transfer- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
put
public void put(String local, String remote) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload a file to the remote computer- Parameters:
local-remote-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
put
public void put(InputStream in, String remote, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException Upload a file to the remote computer reading from the specified
InputStream. The InputStream is closed, even if the operation fails.- Parameters:
in- the InputStream being readremote- the path/name of the destination fileprogress-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledException
-
put
@Deprecated public void put(InputStream in, String remote, FileTransferProgress progress, long position) throws SftpStatusException, SshException, TransferCancelledException Deprecated. -
put
public void put(InputStream in, String remote, FileTransferProgress progress, long position, long length) throws SftpStatusException, SshException, TransferCancelledException -
getOutputStream
Create an OutputStream for writing to a remote file.- Parameters:
remotefile-- Returns:
- OutputStream
- Throws:
SftpStatusExceptionSshException
-
put
public void put(InputStream in, String remote, long position) throws SftpStatusException, SshException, TransferCancelledException Upload the contents of an InputStream to the remote computer.- Parameters:
in-remote-position-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledException
-
put
public void put(InputStream in, String remote) throws SftpStatusException, SshException, TransferCancelledException Upload the contents of an InputStream to the remote computer.- Parameters:
in-remote-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledException
-
chown
Sets the user ID to owner for the file or directory.
- Parameters:
uid- numeric user id of the new ownerpath- the path to the remote file/directory- Throws:
SftpStatusExceptionSshExceptionTransferCancelledException
-
chgrp
Sets the group ID for the file or directory.
- Parameters:
gid- the numeric group id for the new grouppath- the path to the remote file/directory- Throws:
SftpStatusExceptionSshException
-
chmod
public void chmod(PosixPermissions permissions, String path) throws SftpStatusException, SshException Changes the access permissions or modes of the specified file or directory.
Modes determine who can read, change or execute a file.
- Parameters:
permissions- the absolute mode of the file/directorypath- the path to the file/directory on the remote server- Throws:
SftpStatusExceptionSshException- See Also:
-
chmod
@Deprecated(since="3.1.0") public void chmod(int permissions, String path) throws SftpStatusException, SshException Deprecated.Changes the access permissions or modes of the specified file or directory.
Modes determine who can read, change or execute a file.
Absolute modes are octal numbers specifying the complete list of attributes for the files; you specify attributes by OR'ing together these bits. 0400 Individual read 0200 Individual write 0100 Individual execute (or list directory) 0040 Group read 0020 Group write 0010 Group execute 0004 Other read 0002 Other write 0001 Other execute
Now deprecated, it is recommended
PosixPermissionsandPosixPermissions.PosixPermissionsBuilderbe used instead.- Parameters:
permissions- the absolute mode of the file/directorypath- the path to the file/directory on the remote server- Throws:
SftpStatusExceptionSshException
-
umask
Sets the umask for this client.
To give yourself full permissions for both files and directories and prevent the group and other users from having access: umask("077"); This subtracts 077 from the system defaults for files and directories 666 and 777. Giving a default access permissions for your files of 600 (rw-------) and for directories of 700 (rwx------). To give all access permissions to the group and allow other users read and execute permission: umask("002"); This subtracts 002 from the system defaults to give a default access permission for your files of 664 (rw-rw-r--) and for your directories of 775 (rwxrwxr-x). To give the group and other users all access except write access: umask("022"); This subtracts 022 from the system defaults to give a default access permission for your files of 644 (rw-r--r--) and for your directories of 755 (rwxr-xr-x).- Parameters:
umask-- Throws:
SshException
-
rename
Rename a file on the remote computer.
- Parameters:
oldpath- the old pathnewpath- the new path- Throws:
SftpStatusExceptionSshException
-
rm
Remove a file or directory from the remote computer.
- Parameters:
path- the path of the remote file/directory- Throws:
SftpStatusExceptionSshException
-
rm
public void rm(String path, boolean force, boolean recurse) throws SftpStatusException, SshException Remove a file or directory on the remote computer with options to force deletion of existing files and recursion.- Parameters:
path-force-recurse-- Throws:
SftpStatusExceptionSshException
-
symlink
Create a symbolic link on the remote computer.
- Parameters:
path- the path to the existing filelink- the new link- Throws:
SftpStatusExceptionSshException
-
stat
Returns the attributes of the file from the remote computer.
- Parameters:
path- the path of the file on the remote computer- Returns:
- the attributes
- Throws:
SftpStatusExceptionSshException
-
statLink
Returns the attributes of the link from the remote computer.
- Parameters:
path- the path of the file on the remote computer- Returns:
- the attributes
- Throws:
SftpStatusExceptionSshException
-
getAbsolutePath
Get the absolute path for a file.- Parameters:
path-- Returns:
- String
- Throws:
SftpStatusExceptionSshException
-
verifyFiles
public boolean verifyFiles(String localFile, String remoteFile) throws SftpStatusException, SshException, IOException, PermissionDeniedException Verify a local and remote file. Requires a minimum SFTP version of 5 and/or support of the "md5-hash" extension- Parameters:
localFile-remoteFile-- Returns:
- Throws:
SftpStatusExceptionSshExceptionPermissionDeniedExceptionIOException
-
verifyFiles
public boolean verifyFiles(String localFile, String remoteFile, long offset, long length) throws SftpStatusException, SshException, IOException, PermissionDeniedException Verify a local and remote file. Requires a minimum SFTP version of 5 and/or support of the "md5-hash" extension.- Parameters:
localFile-remoteFile-offset-length-- Returns:
- Throws:
SftpStatusExceptionSshExceptionPermissionDeniedExceptionIOException
-
quit
Close the SFTP client.
- Throws:
SshException
-
exit
Close the SFTP client.
- Throws:
SshException
-
putLocalDirectory
public DirectoryOperation putLocalDirectory(String localdir, String remotedir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Copy the contents of a local directory into a remote directory.- Parameters:
localdir- the path to the local directoryremotedir- the remote directory which will receive the contentsrecurse- recurse through child folderssync- synchronize the directories by removing files on the remote server that do not exist locallycommit- actually perform the operation. If false a DirectoryOperation will be returned so that the operation can be evaluated and no actual files will be created/transfered.progress-- Returns:
- DirectoryOperation
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
formatLongname
Format a String with the details of the file.-rwxr-xr-x 1 mjos staff 348911 Mar 25 14:29 t-filexfer
- Parameters:
file-- Returns:
- String
- Throws:
SftpStatusExceptionSshException
-
formatLongname
Format a String with the details of the file.-rwxr-xr-x 1 mjos staff 348911 Mar 25 14:29 t-filexfer
- Parameters:
attrs-filename-- Returns:
- String
-
getRemoteDirectory
public DirectoryOperation getRemoteDirectory(String remotedir, String localdir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Copy the contents of a remote directory to a local directory- Parameters:
remotedir- the remote directory whose contents will be copied.localdir- the local directory to where the contents will be copiedrecurse- recurse into child folderssync- synchronized the directories by removing files and directories that do not exist on the remote server.commit- actually perform the operation. If false the operation will be processed and a DirectoryOperation will be returned without actually transfering any files.progress-- Returns:
- DirectoryOperation
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
getFiles
public SftpFile[] getFiles(String remote) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote files to the local computer
When RegExpSyntax is set to NoSyntax the getFiles() methods act identically to the get() methods except for a different return type.
When RegExpSyntax is set to GlobSyntax or Perl5Syntax, getFiles() treats 'remote' as a regular expression, and gets all the files in 'remote''s parent directory that match the pattern. The default parent directory of remote is the remote cwd unless 'remote' contains file seperators(/).
Examples can be found in SftpConnect.java
Code Example:
// change reg exp syntax from default SftpClient.NoSyntax (no reg exp matching) // to SftpClient.GlobSyntax sftp.setRegularExpressionSyntax(SftpClient.GlobSyntax); // get all .doc files with 'rfc' in their names, in the 'docs/unsorted/' folder // relative to the remote cwd, and copy them to the local cwd. sftp.getFiles("docs/unsorted/*rfc*.doc");- Parameters:
remote- the regular expression path to the remote file- Returns:
- the downloaded files' attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
getFiles
public SftpFile[] getFiles(String remote, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote files to the local computer
- Parameters:
remote- the regular expression path to the remote fileresume- attempt to resume an interrupted download- Returns:
- the downloaded files' attributes
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
getFiles
public SftpFile[] getFiles(String remote, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote files to the local computer.
- Parameters:
remote- the regular expression path to the remote fileprogress-- Returns:
- SftpFile[]
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
getFiles
public SftpFile[] getFiles(String remote, FileTransferProgress progress, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote files to the local computer.
- Parameters:
remote- the regular expression path to the remote fileprogress-resume- attempt to resume a interrupted download- Returns:
- SftpFile[]
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
getFiles
public SftpFile[] getFiles(String remote, String local) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote files into the local file.- Parameters:
remote-local-- Returns:
- SftpFile[]
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
getFiles
public SftpFile[] getFiles(String remote, String local, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote files into the local file.- Parameters:
remote-local-resume- attempt to resume an interrupted download- Returns:
- SftpFile[]
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
getFiles
public SftpFile[] getFiles(String remote, String local, FileTransferProgress progress, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Download the remote file to the local computer. If the paths provided are not absolute the current working directory is used.
- Parameters:
remote- the regular expression path/name of the remote fileslocal- the path/name to place the file on the local computerprogress-- Returns:
- SftpFile[]
- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
putFiles
public void putFiles(String local) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload the contents of an InputStream to the remote computer.
When RegExpSyntax is set to NoSyntax the putFiles() methods act identically to the put() methods except for a different return type.
When RegExpSyntax is set to GlobSyntax or Perl5Syntax, putFiles() treats 'local' as a regular expression, and gets all the files in 'local''s parent directory that match the pattern. The default parent directory of local is the local cwd unless 'local' contains file seperators.
Examples can be found in SftpConnect.java
Code Example:
// change reg exp syntax from default SftpClient.NoSyntax (no reg exp matching) // to SftpClient.GlobSyntax sftp.setRegularExpressionSyntax(SftpClient.GlobSyntax); // put all .doc files with 'rfc' in their names, in the 'docs/unsorted/' folder // relative to the local cwd, and copy them to the remote cwd. sftp.putFiles("docs/unsorted/*rfc*.doc");- Parameters:
local-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
putFiles
public void putFiles(String local, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload files to the remote computer- Parameters:
local-resume- attempt to resume after an interrupted transfer- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
putFiles
public void putFiles(String local, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload files to the remote computer
- Parameters:
local- the regular expression path/name of the local filesprogress-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
putFiles
public void putFiles(String local, FileTransferProgress progress, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload files to the remote computer
- Parameters:
local- the regular expression path/name of the local filesprogress-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
putFiles
public void putFiles(String local, String remote) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload files to the remote computer- Parameters:
local-remote-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
putFiles
public void putFiles(String local, String remote, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload files to the remote computer- Parameters:
local-remote-resume- attempt to resume after an interrupted transfer- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
putFiles
public void putFiles(String local, String remote, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException Upload files to the remote computer. If the paths provided are not absolute the current working directory is used.
- Parameters:
local- the regular expression path/name of the local filesremote- the path/name of the destination fileprogress-- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-
putFiles
public void putFiles(String local, String remote, FileTransferProgress progress, boolean resume) throws SftpStatusException, SshException, TransferCancelledException, IOException, PermissionDeniedException make local copies of some of the variables, then call putfilematches, which calls "put" on each file that matches the regexp local.- Parameters:
local- the regular expression path/name of the local filesremote- the path/name of the destination fileprogress-resume- attempt to resume after an interrupted transfer- Throws:
SftpStatusExceptionSshExceptionTransferCancelledExceptionPermissionDeniedExceptionIOException
-