Class SftpClient
- All Implemented Interfaces:
Closeable
,AutoCloseable
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default buffer sizestatic final int
Specifies that the remote server is using \r as its newline convention when used withsetRemoteEOL(int)
static final int
Specifies that the remote server is using \r\n as its newline convention when used withsetRemoteEOL(int)
static final int
Specifies that the remote server is using \n as its newline convention when used withsetRemoteEOL(int)
static final int
static final int
Instructs the client to use a binary transfer mode when used withsetTransferMode(int)
static final int
Instructs the client to use a text transfer mode when used withsetTransferMode(int)
.static final int
constants for setting the regular expression syntax.static final int
-
Constructor Summary
ConstructorsConstructorDescriptionSftpClient
(SshClient ssh) Deprecated, for removal: This API element is subject to removal in a future version.SftpClient
(SshClient ssh, com.sshtools.common.files.AbstractFileFactory<?> fileFactory) Deprecated, for removal: This API element is subject to removal in a future version.SftpClient
(com.sshtools.common.ssh.SshConnection con) Deprecated, for removal: This API element is subject to removal in a future version.SftpClient
(com.sshtools.common.ssh.SshConnection con, com.sshtools.common.files.AbstractFileFactory<?> fileFactory) Deprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCustomRoot
(String rootPath) Deprecated, for removal: This API element is subject to removal in a future version.void
append
(InputStream in, String remote) void
append
(InputStream in, String remote, FileTransferProgress progress) Deprecated.void
append
(InputStream in, String remote, FileTransferProgress progress, long length) void
void
append
(String local, String remote, FileTransferProgress progress) Deprecated.void
append
(String local, String remote, FileTransferProgress progress, long length) void
Changes the working directory on the remote server, or the user's default directory ifnull
or any empty string is provided as the directory path.void
cdup()
Change the working directory to the parent directoryvoid
Sets the group ID for the file or directory.void
Deprecated.void
Changes the access permissions or modes of the specified file or directory.void
Sets the user ID to owner for the file or directory.void
Sets the user ID to owner for the file or directory.void
close()
void
copyRemoteData
(SftpFile sourceFile, com.sshtools.common.util.UnsignedInteger64 fromOffset, com.sshtools.common.util.UnsignedInteger64 length, SftpFile destinationFile, com.sshtools.common.util.UnsignedInteger64 toOffset) Deprecated, for removal: This API element is subject to removal in a future version.void
copyRemoteFile
(String sourceFile, String destinationFile, boolean overwriteDestination) protected byte[]
doCheckFileHandle
(String filename, long offset, long length, RemoteHash algorithm) protected byte[]
doCheckHashHandle
(byte[] handle, long offset, long length, RemoteHash algorithm) protected byte[]
doMD5HashHandle
(byte[] handle, long offset, long length, byte[] quickCheck) boolean
Determine if a path exists.void
exit()
Close the SFTP client.static String
formatLongname
(SftpFile file) Format a String with the details of the file.static String
formatLongname
(com.sshtools.common.sftp.SftpFileAttributes attrs, String filename) Format a String with the details of the file.com.sshtools.common.sftp.SftpFileAttributes
Download the remote file to the local computercom.sshtools.common.sftp.SftpFileAttributes
Download the remote file to the local computercom.sshtools.common.sftp.SftpFileAttributes
get
(String path, FileTransferProgress progress) Download the remote file to the local computer.com.sshtools.common.sftp.SftpFileAttributes
get
(String path, FileTransferProgress progress, boolean resume) Download the remote file to the local computer.com.sshtools.common.sftp.SftpFileAttributes
get
(String remote, OutputStream local) Download the remote file into an OutputStream.com.sshtools.common.sftp.SftpFileAttributes
get
(String remote, OutputStream local, long position) Download the remote file into an OutputStream.com.sshtools.common.sftp.SftpFileAttributes
get
(String remote, OutputStream local, FileTransferProgress progress) Download the remote file writing it to the specifiedOutputStream
.com.sshtools.common.sftp.SftpFileAttributes
get
(String remote, OutputStream local, FileTransferProgress progress, long position) Download the remote file writing it to the specifiedOutputStream
.com.sshtools.common.sftp.SftpFileAttributes
Download the remote file into the local file.com.sshtools.common.sftp.SftpFileAttributes
Download the remote file into the local file.com.sshtools.common.sftp.SftpFileAttributes
get
(String remote, String local, FileTransferProgress progress) Download the remote file to the local computer.com.sshtools.common.sftp.SftpFileAttributes
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.com.sshtools.common.files.AbstractFile
Get the default directory (or HOME directory)int
getEOL
(byte[] nl) int
SftpFile[]
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.getHome()
getHomeDirectory
(String username) 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 directoryint
byte[]
getRemoteHash
(byte[] handle) Deprecated.byte[]
getRemoteHash
(byte[] handle, long offset, long length, byte[] quickCheck) Deprecated.byte[]
getRemoteHash
(byte[] handle, long offset, long length, RemoteHash algorithm) byte[]
getRemoteHash
(byte[] handle, RemoteHash algorithm) byte[]
getRemoteHash
(String remoteFile) Deprecated.byte[]
getRemoteHash
(String remoteFile, long offset, long length, byte[] quickCheck) Deprecated.byte[]
getRemoteHash
(String path, long offset, long length, RemoteHash algorithm) byte[]
getRemoteHash
(String path, RemoteHash algorithm) Returns the instance of the AbstractSftpChannel used by this classgetSymbolicLinkTarget
(String linkpath) Get the target path of a symbolic link.int
void
boolean
isClosed()
Returns the state of the SFTP client.boolean
boolean
Determine whether the file object is pointing to a symbolic link that is pointing to a directory.void
Changes 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[]
SftpFile[]
Return an iterator for the current working directory.lsIterator
(String path) Return an iterator for the path provided.SftpFile[]
matchRemoteFiles
(String remote) Called by getFileMatches() to do regular expression pattern matching on the files in 'remote''s parent directory.void
Creates a new directory on the remote server.void
Create a directory or set of directories.openDirectory
(String path) protected byte[]
processCheckFileResponse
(SftpMessage resp, RemoteHash algorithm) void
put
(InputStream in, String remote) Upload the contents of an InputStream to the remote computer.void
put
(InputStream in, String remote, long position) Upload the contents of an InputStream to the remote computer.void
put
(InputStream in, String remote, FileTransferProgress progress) Upload a file to the remote computer reading from the specifiedInputStream
.void
put
(InputStream in, String remote, FileTransferProgress progress, long position) Deprecated.void
put
(InputStream in, String remote, FileTransferProgress progress, long position, long length) Upload a file to the remote computer reading from the specifiedInputStream
.void
Upload a file to the remote computervoid
Upload a file to the remote computervoid
put
(String local, FileTransferProgress progress) Upload a file to the remote computer.void
put
(String local, FileTransferProgress progress, boolean resume) Upload a file to the remote computer.void
Upload a file to the remote computervoid
Upload a file to the remote computervoid
put
(String local, String remote, FileTransferProgress progress) Upload a file to the remote computer.void
put
(String local, String remote, FileTransferProgress progress, boolean resume) Upload a file to the remote computer.void
Upload the contents of an InputStream to the remote computer.void
Upload files to the remote computervoid
putFiles
(String local, FileTransferProgress progress) Upload files to the remote computervoid
putFiles
(String local, FileTransferProgress progress, boolean resume) Upload files to the remote computervoid
Upload files to the remote computervoid
Upload files to the remote computervoid
putFiles
(String local, String remote, FileTransferProgress progress) Upload files to the remote computer.void
putFiles
(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.void
quit()
Close the SFTP client.readDirectory
(SftpHandle dir) void
relativeSymlink
(String path, String link) Create a symbolic link on the remote computer.void
removeCustomRoot
(String rootPath) Deprecated, for removal: This API element is subject to removal in a future version.void
Rename a file on the remote computer.void
Rename a file on the remote computer, optionally using posix semantics that allow files to be renamed even if the destination path exists.void
Remove a file or directory from the remote computer.void
Remove a file or directory on the remote computer with options to force deletion of existing files and recursion.void
Remove a directory, will fail if the directory has contents.void
setBlockSize
(int blocksize) Sets the block size used when transferring files, defaults to the optimized setting of 32768.void
setBufferSize
(int buffersize) Set the size of the buffer which is used to read from the local file system.void
setForceRemoteEOL
(boolean forceRemoteEOL) Override automatic detection of the remote EOL (any SFTP version).void
setLocalEOL
(int eolMode) Override the default local system EOL for text mode files.void
setMaxAsyncRequests
(int asyncRequests) Set the maximum number of asynchronous requests that are outstanding at any one time.void
setRegularExpressionSyntax
(int syntax) sets the type of regular expression matching to perform on gets and putsvoid
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.void
setStripEOL
(boolean stripEOL) Strip all line endings in preference of the target system EOL setting.void
setTransferMode
(int transferMode) Sets the transfer mode for current operations.com.sshtools.common.sftp.SftpFileAttributes
Returns the attributes of the file from the remote computer.com.sshtools.common.sftp.SftpFileAttributes
Returns the attributes of the link from the remote computer.void
Create a symbolic link on the remote computer.int
umask
(int umask) Sets the umask used by this client.void
Sets the umask for this client.
boolean
verifyFiles
(String localFile, String remoteFile) Verify a local and remote file.boolean
verifyFiles
(String localFile, String remoteFile, long offset, long length) Verify a local and remote file.boolean
verifyFiles
(String localFile, String remoteFile, long offset, long length, RemoteHash algorithm) boolean
verifyFiles
(String localFile, String remoteFile, RemoteHash algorithm) visit
(String path, FileVisitor<SftpFile> visitor)
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault buffer size- See Also:
-
MODE_BINARY
public static final int MODE_BINARYInstructs the client to use a binary transfer mode when used withsetTransferMode(int)
- See Also:
-
MODE_TEXT
public static final int MODE_TEXTInstructs the client to use a text transfer mode when used withsetTransferMode(int)
.- See Also:
-
EOL_CRLF
public static final int EOL_CRLFSpecifies that the remote server is using \r\n as its newline convention when used with
setRemoteEOL(int)
- See Also:
-
EOL_LF
public static final int EOL_LFSpecifies that the remote server is using \n as its newline convention when used with
setRemoteEOL(int)
- See Also:
-
EOL_CR
public static final int EOL_CRSpecifies that the remote server is using \r as its newline convention when used with
setRemoteEOL(int)
- See Also:
-
NoSyntax
public static final int NoSyntaxconstants for setting the regular expression syntax.- See Also:
-
GlobSyntax
public static final int GlobSyntax- See Also:
-
Perl5Syntax
public static final int Perl5Syntax- See Also:
-
-
Constructor Details
-
SftpClient
@Deprecated(since="3.1.0", forRemoval=true) public SftpClient(com.sshtools.common.ssh.SshConnection con) throws com.sshtools.common.ssh.SshException, com.sshtools.common.permissions.PermissionDeniedException, IOException Deprecated, for removal: This API element is subject to removal in a future version.- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
SftpClient
@Deprecated(since="3.1.0", forRemoval=true) public SftpClient(com.sshtools.common.ssh.SshConnection con, com.sshtools.common.files.AbstractFileFactory<?> fileFactory) throws com.sshtools.common.permissions.PermissionDeniedException, IOException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.- Throws:
com.sshtools.common.permissions.PermissionDeniedException
IOException
com.sshtools.common.ssh.SshException
-
SftpClient
@Deprecated(since="3.1.0", forRemoval=true) public SftpClient(SshClient ssh) throws com.sshtools.common.ssh.SshException, com.sshtools.common.permissions.PermissionDeniedException, IOException Deprecated, for removal: This API element is subject to removal in a future version.- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
SftpClient
@Deprecated(since="3.1.0", forRemoval=true) public SftpClient(SshClient ssh, com.sshtools.common.files.AbstractFileFactory<?> fileFactory) throws com.sshtools.common.ssh.SshException, com.sshtools.common.permissions.PermissionDeniedException, IOException Deprecated, for removal: This API element is subject to removal in a future version.- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
-
Method Details
-
setBlockSize
public void setBlockSize(int blocksize) 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
- block size
-
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
-
setStripEOL
public void setStripEOL(boolean stripEOL) Strip all line endings in preference of the target system EOL setting.- Parameters:
stripEOL
-
-
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
public void setMaxAsyncRequests(int asyncRequests) 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
- aync requests
-
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
- umask- Returns:
- the previous umask value
-
openFile
public SftpHandle openFile(String fileName) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
openFile
public SftpHandle openFile(String fileName, int flags) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
openDirectory
public SftpHandle openDirectory(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
readDirectory
public List<SftpFile> readDirectory(SftpHandle dir) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
cd
public void cd(String dir) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Changes the working directory on the remote server, or the user's default directory if
null
or 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 existcom.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getDefaultDirectory
public String getDefaultDirectory() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshExceptionGet the default directory (or HOME directory)
- Returns:
- String
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
cdup
public void cdup() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshExceptionChange the working directory to the parent directory- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
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
-- See Also:
-
SftpClientBuilder#withCustomRoots(String)
-
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
-- See Also:
-
SftpClientBuilder#withCustomRoots(String)
-
mkdir
public void mkdir(String dir) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException 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
mkdirs
method.- Parameters:
dir
- the name of the new directory- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
mkdirs
public void mkdirs(String dir) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException 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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
isDirectoryOrLinkedDirectory
public boolean isDirectoryOrLinkedDirectory(SftpFile file) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Determine whether the file object is pointing to a symbolic link that is pointing to a directory.- Returns:
- boolean
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
exists
public boolean exists(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Determine if a path exists.- Returns:
- boolean
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
pwd
public String pwd() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshExceptionReturns the absolute path name of the current remote working directory.
- Returns:
- the absolute path of the remote working directory.
- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
ls
public SftpFile[] ls() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshExceptionList 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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
ls
public SftpFile[] ls(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException 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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
ls
public SftpFile[] ls(String filter, boolean regexFilter, int maximumFiles) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
ls
public SftpFile[] ls(String path, String filter, boolean regexFilter, int maximumFiles) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
lsIterator
public Iterator<SftpFile> lsIterator() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshExceptionReturn an iterator for the current working directory. This method improves memory usage by only getting paged contents of the directory.- Returns:
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
lsIterator
public Iterator<SftpFile> lsIterator(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Return an iterator for the path provided. This method improves memory usage by only getting paged contents of the directory.- Parameters:
path
-- Returns:
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
lcd
public void lcd(String path) throws com.sshtools.common.sftp.SftpStatusException, IOException, com.sshtools.common.permissions.PermissionDeniedException Changes the local working directory.
- Parameters:
path
- the path to the new working directory- Throws:
com.sshtools.common.sftp.SftpStatusException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
lpwd
Returns the absolute path to the local working directory.
- Returns:
- the absolute path of the local working directory.
- Throws:
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
getCurrentWorkingDirectory
public com.sshtools.common.files.AbstractFile getCurrentWorkingDirectory() -
get
public com.sshtools.common.sftp.SftpFileAttributes get(String path, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException Download the remote file to the local computer.
- Parameters:
path
- the path to the remote fileprogress
-- Returns:
- the downloaded file's attributes
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
get
public com.sshtools.common.sftp.SftpFileAttributes get(String path, FileTransferProgress progress, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
get
public com.sshtools.common.sftp.SftpFileAttributes get(String path, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
get
public com.sshtools.common.sftp.SftpFileAttributes get(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException Download the remote file to the local computer
- Parameters:
path
- the path to the remote file- Returns:
- the downloaded file's attributes
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
getSymbolicLinkTarget
public String getSymbolicLinkTarget(String linkpath) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Get the target path of a symbolic link.- Parameters:
linkpath
-- Returns:
- String
- Throws:
com.sshtools.common.ssh.SshException
- if the remote SFTP version is < 3 an exception is thrown as this feature is not supported by previous versions of the protocol.com.sshtools.common.sftp.SftpStatusException
-
get
public com.sshtools.common.sftp.SftpFileAttributes get(String remote, String local, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
get
public com.sshtools.common.sftp.SftpFileAttributes get(String remote, String local, FileTransferProgress progress, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
getRemoteNewline
- Throws:
com.sshtools.common.sftp.SftpStatusException
-
getRemoteEOL
public int getRemoteEOL() throws com.sshtools.common.sftp.SftpStatusException- Throws:
com.sshtools.common.sftp.SftpStatusException
-
getEOL
- Throws:
com.sshtools.common.sftp.SftpStatusException
-
getEOL
public int getEOL(byte[] nl) throws com.sshtools.common.sftp.SftpStatusException - Throws:
com.sshtools.common.sftp.SftpStatusException
-
get
public com.sshtools.common.sftp.SftpFileAttributes get(String remote, String local, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
get
public com.sshtools.common.sftp.SftpFileAttributes get(String remote, String local) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException Download the remote file into the local file.- Parameters:
remote
-local
-- Returns:
- the downloaded file's attributes
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
get
public com.sshtools.common.sftp.SftpFileAttributes get(String remote, OutputStream local, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
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
public SftpFile[] matchRemoteFiles(String remote) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Called by getFileMatches() to do regular expression pattern matching on the files in 'remote''s parent directory.- Parameters:
remote
-- Returns:
- SftpFile[]
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
get
public com.sshtools.common.sftp.SftpFileAttributes get(String remote, OutputStream local, FileTransferProgress progress, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
getInputStream
public InputStream getInputStream(String remotefile, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Create an InputStream for reading a remote file.- Parameters:
remotefile
-position
-- Returns:
- InputStream
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getInputStream
public InputStream getInputStream(String remotefile) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Create an InputStream for reading a remote file.- Parameters:
remotefile
-- Returns:
- InputStream
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
get
public com.sshtools.common.sftp.SftpFileAttributes get(String remote, OutputStream local, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
get
public com.sshtools.common.sftp.SftpFileAttributes get(String remote, OutputStream local) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Download the remote file into an OutputStream.- Parameters:
remote
-local
-- Returns:
- the downloaded file's attributes
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
isClosed
public boolean isClosed()Returns the state of the SFTP client. The client is closed if the underlying session channel is closed. Invoking the
quit
method 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 com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException Upload a file to the remote computer.
- Parameters:
local
- the path/name of the local fileprogress
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
put
public void put(String local, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException Upload a file to the remote computer.
- Parameters:
local
- the path/name of the local fileprogress
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
put
public void put(String local) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException Upload a file to the remote computer- Parameters:
local
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
put
public void put(String local, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException Upload a file to the remote computer- Parameters:
local
-resume
- attempt to resume after an interrupted transfer- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
put
public void put(String local, String remote, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
append
public void append(InputStream in, String remote) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
append
@Deprecated public void append(InputStream in, String remote, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Deprecated.- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
append
public void append(InputStream in, String remote, FileTransferProgress progress, long length) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
put
public void put(String local, String remote, FileTransferProgress progress, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
append
public void append(String local, String remote) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
append
@Deprecated public void append(String local, String remote, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException Deprecated.- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
append
public void append(String local, String remote, FileTransferProgress progress, long length) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
put
public void put(String local, String remote, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException Upload a file to the remote computer- Parameters:
local
-remote
-resume
- attempt to resume after an interrupted transfer- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
put
public void put(String local, String remote) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException Upload a file to the remote computer- Parameters:
local
-remote
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
put
public void put(InputStream in, String remote, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Upload a file to the remote computer reading from the specified
InputStream
. The InputStream is closed, even if the operation fails. TheFileTransferProgress
will be indeterminate, i.eFileTransferProgress.started(long, String)
will be called with alength
of-1
, as it is not possible to generically determine the length of anInputStream
. It is recommended you useput(InputStream, String, FileTransferProgress, long, long)
instead to provide the size when known.- Parameters:
in
- the InputStream being readremote
- the path/name of the destination fileprogress
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
put
@Deprecated public void put(InputStream in, String remote, FileTransferProgress progress, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Deprecated.- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
put
public void put(InputStream in, String remote, FileTransferProgress progress, long position, long length) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Upload a file to the remote computer reading from the specified
InputStream
. The InputStream is closed, even if the operation fails. TheFileTransferProgress
will be indeterminate if you pass alength
of-1
. to provide the size when known.- Parameters:
in
- the InputStream being readremote
- the path/name of the destination fileprogress
- progressposition
- position to start atlength
- the number of bytes that will be transferred or -1 if unknown.- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
getOutputStream
public OutputStream getOutputStream(String remotefile) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Create an OutputStream for writing to a remote file.- Parameters:
remotefile
-- Returns:
- OutputStream
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
put
public void put(InputStream in, String remote, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Upload the contents of an InputStream to the remote computer.- Parameters:
in
-remote
-position
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
put
public void put(InputStream in, String remote) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Upload the contents of an InputStream to the remote computer.- Parameters:
in
-remote
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
chown
public void chown(String uid, String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException 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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
chown
public void chown(String uid, String gid, String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException 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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
-
chgrp
public void chgrp(String gid, String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException 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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
chmod
public void chmod(com.sshtools.common.sftp.PosixPermissions permissions, String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
- See Also:
-
PosixPermissions
PosixPermissions.PosixPermissionsBuilder
-
chmod
@Deprecated(since="3.1.0") public void chmod(int permissions, String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.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
PosixPermissions
andPosixPermissions.PosixPermissionsBuilder
be used instead.- Parameters:
permissions
- the absolute mode of the file/directorypath
- the path to the file/directory on the remote server- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
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:
com.sshtools.common.ssh.SshException
-
rename
public void rename(String oldpath, String newpath, boolean posix) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Rename a file on the remote computer, optionally using posix semantics that allow files to be renamed even if the destination path exists. The server must support posix-rename@openssh.com SFTP extension in order to use the posix operation.- Parameters:
oldpath
-newpath
-posix
-- Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
copyRemoteFile
public void copyRemoteFile(String sourceFile, String destinationFile, boolean overwriteDestination) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
IOException
-
copyRemoteData
@Deprecated(since="3.1.0", forRemoval=true) public void copyRemoteData(SftpFile sourceFile, com.sshtools.common.util.UnsignedInteger64 fromOffset, com.sshtools.common.util.UnsignedInteger64 length, SftpFile destinationFile, com.sshtools.common.util.UnsignedInteger64 toOffset) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException Deprecated, for removal: This API element is subject to removal in a future version.Copy remotely from one file to another (when supported by extension).- Parameters:
sourceFile
- source filefromOffset
- from offsetlength
- lengthdestinationFile
- destination filetoOffset
- to offset- Throws:
com.sshtools.common.sftp.SftpStatusException
- on SFTP errorcom.sshtools.common.ssh.SshException
- on SSH errorIOException
- on IO error- See Also:
-
rename
public void rename(String oldpath, String newpath) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Rename a file on the remote computer.
- Parameters:
oldpath
- the old pathnewpath
- the new path- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
rm
public void rm(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Remove a file or directory from the remote computer.
- Parameters:
path
- the path of the remote file/directory- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
rm
public void rm(String path, boolean force, boolean recurse) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
rmdir
public void rmdir(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Remove a directory, will fail if the directory has contents.- Parameters:
path
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
symlink
public void symlink(String path, String link) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Create a symbolic link on the remote computer.
- Parameters:
path
- the path to the existing filelink
- the new link- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
relativeSymlink
public void relativeSymlink(String path, String link) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Create a symbolic link on the remote computer.
- Parameters:
path
- the path to the existing filelink
- the new link- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
stat
public com.sshtools.common.sftp.SftpFileAttributes stat(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException 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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
statLink
public com.sshtools.common.sftp.SftpFileAttributes statLink(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException 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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getAbsolutePath
public String getAbsolutePath(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Get the absolute path for a file.- Parameters:
path
-- Returns:
- String
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
verifyFiles
public boolean verifyFiles(String localFile, String remoteFile) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
verifyFiles
public boolean verifyFiles(String localFile, String remoteFile, RemoteHash algorithm) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException, com.sshtools.common.permissions.PermissionDeniedException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
verifyFiles
public boolean verifyFiles(String localFile, String remoteFile, long offset, long length) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
verifyFiles
public boolean verifyFiles(String localFile, String remoteFile, long offset, long length, RemoteHash algorithm) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException, com.sshtools.common.permissions.PermissionDeniedException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
getRemoteHash
@Deprecated public byte[] getRemoteHash(String remoteFile) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated.- Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getRemoteHash
@Deprecated public byte[] getRemoteHash(String remoteFile, long offset, long length, byte[] quickCheck) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated.- Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getRemoteHash
@Deprecated public byte[] getRemoteHash(byte[] handle) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated.- Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getRemoteHash
@Deprecated public byte[] getRemoteHash(byte[] handle, long offset, long length, byte[] quickCheck) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated.- Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getRemoteHash
public byte[] getRemoteHash(byte[] handle, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getRemoteHash
public byte[] getRemoteHash(byte[] handle, long offset, long length, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getRemoteHash
public byte[] getRemoteHash(String path, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getRemoteHash
public byte[] getRemoteHash(String path, long offset, long length, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
doCheckHashHandle
protected byte[] doCheckHashHandle(byte[] handle, long offset, long length, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
doCheckFileHandle
protected byte[] doCheckFileHandle(String filename, long offset, long length, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
processCheckFileResponse
protected byte[] processCheckFileResponse(SftpMessage resp, RemoteHash algorithm) throws IOException - Throws:
IOException
-
doMD5HashHandle
protected byte[] doMD5HashHandle(byte[] handle, long offset, long length, byte[] quickCheck) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
quit
public void quit() throws com.sshtools.common.ssh.SshExceptionClose the SFTP client.
- Throws:
com.sshtools.common.ssh.SshException
-
exit
public void exit() throws com.sshtools.common.ssh.SshExceptionClose the SFTP client.
- Throws:
com.sshtools.common.ssh.SshException
-
putLocalDirectory
public DirectoryOperation putLocalDirectory(String localdir, String remotedir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
IOException
-
formatLongname
public static String formatLongname(SftpFile file) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException 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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
formatLongname
public static String formatLongname(com.sshtools.common.sftp.SftpFileAttributes attrs, String filename) 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 IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.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:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
-
getFiles
public SftpFile[] getFiles(String remote) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.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:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
-
getFiles
public SftpFile[] getFiles(String remote, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.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:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
-
getFiles
public SftpFile[] getFiles(String remote, FileTransferProgress progress) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException Download the remote files to the local computer.
- Parameters:
remote
- the regular expression path to the remote fileprogress
-- Returns:
- SftpFile[]
- Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
-
getFiles
public SftpFile[] getFiles(String remote, FileTransferProgress progress, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.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:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
-
getFiles
public SftpFile[] getFiles(String remote, String local) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException Download the remote files into the local file.- Parameters:
remote
-local
-- Returns:
- SftpFile[]
- Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
-
getFiles
public SftpFile[] getFiles(String remote, String local, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException Download the remote files into the local file.- Parameters:
remote
-local
-resume
- attempt to resume an interrupted download- Returns:
- SftpFile[]
- Throws:
IOException
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
-
getFiles
public SftpFile[] getFiles(String remote, String local, FileTransferProgress progress, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
IOException
com.sshtools.common.ssh.SshException
TransferCancelledException
com.sshtools.common.permissions.PermissionDeniedException
-
putFiles
public void putFiles(String local) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
putFiles
public void putFiles(String local, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException Upload files to the remote computer- Parameters:
local
-resume
- attempt to resume after an interrupted transfer- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
putFiles
public void putFiles(String local, FileTransferProgress progress) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException Upload files to the remote computer
- Parameters:
local
- the regular expression path/name of the local filesprogress
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
putFiles
public void putFiles(String local, FileTransferProgress progress, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException Upload files to the remote computer
- Parameters:
local
- the regular expression path/name of the local filesprogress
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
putFiles
public void putFiles(String local, String remote) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException Upload files to the remote computer- Parameters:
local
-remote
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
putFiles
public void putFiles(String local, String remote, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException Upload files to the remote computer- Parameters:
local
-remote
-resume
- attempt to resume after an interrupted transfer- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
putFiles
public void putFiles(String local, String remote, FileTransferProgress progress) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
putFiles
public void putFiles(String local, String remote, FileTransferProgress progress, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.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:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
IOException
com.sshtools.common.permissions.PermissionDeniedException
-
isConnected
public boolean isConnected() -
hardlink
public void hardlink(String src, String dst) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException - Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
getHomeDirectory
public String getHomeDirectory(String username) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException - Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
makeTemporaryFolder
public String makeTemporaryFolder() throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
getTemporaryFolder
public String getTemporaryFolder() throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
statVFS
public StatVfs statVFS(String path) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException - Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
getHome
public String getHome() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
visit
public FileVisitResult visit(String path, FileVisitor<SftpFile> visitor) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException - Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-