com.mindbright.ssh2
public final class SSH2SFTPClient extends SSH2SFTP implements SSH2SFTP.Callback
read and
write return immediately before the operation has
finished. The asyncWait method waits until all
operations have been completed and must be called before read
buffers are accessed.SSH2SFTP.AsyncListener, SSH2SFTP.Callback, SSH2SFTP.FileAttributes, SSH2SFTP.FileHandle, SSH2SFTP.FileSystemAttributes, SSH2SFTP.SFTPAsyncAbortException, SSH2SFTP.SFTPDisconnectException, SSH2SFTP.SFTPEOFException, SSH2SFTP.SFTPException, SSH2SFTP.SFTPFailureException, SSH2SFTP.SFTPNoSuchFileException, SSH2SFTP.SFTPPacket, SSH2SFTP.SFTPPermissionDeniedException, SSH2SFTP.SFTPUnsupportedExceptionSSH_ATTR_EXTENDED, SSH_ATTR_MODTIME, SSH_ATTR_PERM, SSH_ATTR_SIZE, SSH_ATTR_UIDGID, SSH_FILEXFER_VERSION, SSH_FX_BAD_MESSAGE, SSH_FX_CONNECTION_LOST, SSH_FX_EOF, SSH_FX_FAILURE, SSH_FX_INVALID_HANDLE, SSH_FX_NO_CONNECTION, SSH_FX_NO_SUCH_FILE, SSH_FX_OK, SSH_FX_OP_UNSUPPORTED, SSH_FX_PERMISSION_DENIED, SSH_FXF_APPEND, SSH_FXF_CREAT, SSH_FXF_EXCL, SSH_FXF_READ, SSH_FXF_TRUNC, SSH_FXF_WRITE, SSH_FXP_ATTRS, SSH_FXP_CLOSE, SSH_FXP_DATA, SSH_FXP_EXTENDED, SSH_FXP_EXTENDED_REPLY, SSH_FXP_FSETSTAT, SSH_FXP_FSTAT, SSH_FXP_HANDLE, SSH_FXP_INIT, SSH_FXP_LSTAT, SSH_FXP_MKDIR, SSH_FXP_NAME, SSH_FXP_OLD_STAT, SSH_FXP_OPEN, SSH_FXP_OPENDIR, SSH_FXP_READ, SSH_FXP_READDIR, SSH_FXP_READLINK, SSH_FXP_REALPATH, SSH_FXP_REMOVE, SSH_FXP_RENAME, SSH_FXP_RMDIR, SSH_FXP_SETSTAT, SSH_FXP_STAT, SSH_FXP_STATUS, SSH_FXP_SYMLINK, SSH_FXP_VERSION, SSH_FXP_WRITE| Constructor and Description |
|---|
SSH2SFTPClient(SSH2Connection connection,
boolean isBlocking)
Create a new SFTP client which connects to the server.
|
SSH2SFTPClient(SSH2Connection connection,
boolean isBlocking,
int maxSize)
Create a new SFTP client which connects to the server.
|
| Modifier and Type | Method and Description |
|---|---|
void |
asyncWait(SSH2SFTP.FileHandle handle)
Wait for all outstanding asynchronous operations on the given
file to complete.
|
void |
close(SSH2SFTP.FileHandle handle)
Close a file.
|
void |
fsetstat(SSH2SFTP.FileHandle handle,
SSH2SFTP.FileAttributes attrs)
Set attributes on an open file.
|
SSH2SFTP.FileAttributes |
fstat(SSH2SFTP.FileHandle handle)
Get attributes of an open file on the server.
|
SSH2SFTP.FileSystemAttributes |
fstatvfs(SSH2SFTP.FileHandle handle)
Get attributes of a filesystem on the server.
|
SSH2SessionChannel |
getSessionChannel() |
void |
hardlink(java.lang.String oldpath,
java.lang.String newpath)
Create a hard link on the server.
|
SSH2SFTP.FileAttributes |
lstat(java.lang.String name)
Get attributes of a file on the server.
|
void |
mkdir(java.lang.String name,
SSH2SFTP.FileAttributes attrs)
Create a new directory on the server.
|
SSH2SFTP.FileHandle |
open(java.lang.String name,
int flags,
SSH2SFTP.FileAttributes attrs)
Open a file on the server.
|
SSH2SFTP.FileHandle |
opendir(java.lang.String path)
Opens a directory on the server.
|
void |
packetReceived(SSH2SFTP.SFTPPacket pkt) |
void |
posixRename(java.lang.String oldName,
java.lang.String newName)
Rename a file on the server with Posix semantics.
|
int |
read(SSH2SFTP.FileHandle handle,
long fileOffset,
byte[] buf,
int off,
int len)
Read data from an open file on the server and stores it in a
local buffer.
|
int |
read(SSH2SFTP.FileHandle handle,
long fileOffset,
java.io.RandomAccessFile fileTarget,
int len)
Read data from an open file on the server and stores it in a
local file.
|
SSH2SFTP.FileAttributes[] |
readdir(SSH2SFTP.FileHandle handle)
Gets a list of files, and other objects, in an open
directory.
|
void |
readFailed(SSH2SFTP.SFTPException e) |
int |
readFully(SSH2SFTP.FileHandle handle,
java.io.OutputStream out)
Read the entire file on the server and store in a local
stream.
|
java.lang.String |
readlink(java.lang.String path)
Read target of a symbolic link
|
SSH2SFTP.FileAttributes |
realpath(java.lang.String nameIn)
Canonalize a given path.
|
void |
remove(java.lang.String name)
Remove a file from the server.
|
void |
rename(java.lang.String oldName,
java.lang.String newName)
Rename a file on the server.
|
void |
restart()
Reopens the connection to the server.
|
void |
rmdir(java.lang.String name)
Removes a directory from the server
|
void |
setstat(java.lang.String name,
SSH2SFTP.FileAttributes attrs)
Set attributes on a file.
|
SSH2SFTP.FileAttributes |
stat(java.lang.String name)
Get attributes of a file on the server.
|
SSH2SFTP.FileSystemAttributes |
statvfs(java.lang.String name)
Get attributes of a filesystem on the server.
|
void |
symlink(java.lang.String linkpath,
java.lang.String targetpath)
Create a symbolic link on the server.
|
void |
terminate()
Terminate the connection and abort any asynchronous calls which
are in progress.
|
void |
write(SSH2SFTP.FileHandle handle,
long fileOffset,
byte[] buf,
int off,
int len)
Write data to a remote file.
|
long |
writeFully(SSH2SFTP.FileHandle handle,
byte[] in,
boolean append)
Write data buffer to a file on the server.
|
long |
writeFully(SSH2SFTP.FileHandle handle,
java.io.InputStream in)
Write an entire stream to a file on the server.
|
long |
writeFully(SSH2SFTP.FileHandle handle,
java.io.InputStream in,
boolean append)
Write an entire stream to a file on the server.
|
protected void |
writeInternal(SSH2SFTP.FileHandle handle,
SSH2SFTP.SFTPPacket pkt,
int len)
Internal write function.
|
public SSH2SFTPClient(SSH2Connection connection, boolean isBlocking) throws SSH2SFTP.SFTPException
connection - Connection to run over.isBlocking - True if read and write operations should be
synchronous.SSH2SFTP.SFTPExceptionpublic SSH2SFTPClient(SSH2Connection connection, boolean isBlocking, int maxSize) throws SSH2SFTP.SFTPException
connection - Connection to run over.isBlocking - True if read and write operations should be
synchronous.maxSize - Max packet size, must be 1..32768.SSH2SFTP.SFTPExceptionpublic void terminate()
public SSH2SessionChannel getSessionChannel()
public void restart()
throws SSH2SFTP.SFTPException
SSH2SFTP.SFTPExceptionpublic SSH2SFTP.FileHandle open(java.lang.String name, int flags, SSH2SFTP.FileAttributes attrs) throws SSH2SFTP.SFTPException
name - Name of fileflags - Mode to open file with. Valid values are
SSH2SFTP.SSH_FXF_*.attrs - File attributes for new files.SSH2SFTP.SFTPExceptionpublic void close(SSH2SFTP.FileHandle handle) throws SSH2SFTP.SFTPException
handle - Handle identifying file.SSH2SFTP.SFTPExceptionpublic void asyncWait(SSH2SFTP.FileHandle handle) throws SSH2SFTP.SFTPException
handle - Handle identifying file.SSH2SFTP.SFTPExceptionpublic int read(SSH2SFTP.FileHandle handle, long fileOffset, java.io.RandomAccessFile fileTarget, int len) throws SSH2SFTP.SFTPException, java.io.IOException
Note that if the client is operating in
asynchronous mode then the method will return before data has been
written to the stream. In this case the asyncWait
method must be called, or the sftp file closed, before the stream
can be closed.
handle - Handle identifying file.fileOffset - Where in the file to start to read.fileTarget - Local file to write the data into.len - Number of bytes to read. Must be less than
maxDataSize, which by default is 32768 bytes.SSH2SFTP.SFTPExceptionjava.io.IOExceptionpublic int read(SSH2SFTP.FileHandle handle, long fileOffset, byte[] buf, int off, int len) throws SSH2SFTP.SFTPException
asyncWait
method must be called, or the file closed, before the data can
be safely accessed.handle - Handle identifying file.fileOffset - Where in the file to start to read.buf - Local buffer to store data in. Must hold
len bytes at the given offset.off - Offset in buffer to store data at.len - Number of bytes to read. Must be less than
maxDataSize, which by default is 32768 bytes.SSH2SFTP.SFTPExceptionpublic int readFully(SSH2SFTP.FileHandle handle, java.io.OutputStream out) throws SSH2SFTP.SFTPException, java.io.IOException
handle - Handle identifying file. The handle will be
closed when the transfer has completed.out - Stream to store data in.SSH2SFTP.SFTPExceptionjava.io.IOExceptionprotected void writeInternal(SSH2SFTP.FileHandle handle, SSH2SFTP.SFTPPacket pkt, int len) throws SSH2SFTP.SFTPException
SSH2SFTP.SFTPExceptionpublic void write(SSH2SFTP.FileHandle handle, long fileOffset, byte[] buf, int off, int len) throws SSH2SFTP.SFTPException
handle - Handle identifying file.fileOffset - Offset to store data at.buf - Buffer containing data to write.off - Offset in buf to read data at.len - Number of bytes to write. Must be less than
maxDataSize, which by default is 32768 bytes.SSH2SFTP.SFTPExceptionpublic long writeFully(SSH2SFTP.FileHandle handle, java.io.InputStream in) throws SSH2SFTP.SFTPException, java.io.IOException
handle - Handle identifying file. The handle will be
closed when the transfer has completed.in - Stream to read data to write from.SSH2SFTP.SFTPExceptionjava.io.IOExceptionpublic long writeFully(SSH2SFTP.FileHandle handle, java.io.InputStream in, boolean append) throws SSH2SFTP.SFTPException, java.io.IOException
handle - Handle identifying file. The handle will be
closed when the transfer has completed.in - Stream to read data to write from.append - if true then the data is written at the end of
the opened file. In this case the handle must have been opened
in append mode.SSH2SFTP.SFTPExceptionjava.io.IOExceptionpublic long writeFully(SSH2SFTP.FileHandle handle, byte[] in, boolean append) throws SSH2SFTP.SFTPException, java.io.IOException
handle - Handle identifying file. The handle will be
closed when the transfer has completed.in - Buffer containing data to write.append - if true then the data is written at the end of
the opened file. In this case the handle must have been opened
in append mode.SSH2SFTP.SFTPExceptionjava.io.IOExceptionpublic SSH2SFTP.FileAttributes lstat(java.lang.String name) throws SSH2SFTP.SFTPException
name - Name of file to get attributes of.SSH2SFTP.SFTPExceptionpublic SSH2SFTP.FileAttributes stat(java.lang.String name) throws SSH2SFTP.SFTPException
name - Name of file to get attributes of.SSH2SFTP.SFTPExceptionpublic SSH2SFTP.FileAttributes fstat(SSH2SFTP.FileHandle handle) throws SSH2SFTP.SFTPException
handle - Handle identifying file.SSH2SFTP.SFTPExceptionpublic void setstat(java.lang.String name,
SSH2SFTP.FileAttributes attrs)
throws SSH2SFTP.SFTPException
name - Name of file to set attributes on.attrs - Attributes to set.SSH2SFTP.SFTPExceptionpublic void fsetstat(SSH2SFTP.FileHandle handle, SSH2SFTP.FileAttributes attrs) throws SSH2SFTP.SFTPException
handle - Handle identifying the file.attrs - Attributes to set.SSH2SFTP.SFTPExceptionpublic SSH2SFTP.FileSystemAttributes statvfs(java.lang.String name) throws SSH2SFTP.SFTPException
name - Path into the filesystem to get data aboutSSH2SFTP.SFTPExceptionpublic SSH2SFTP.FileSystemAttributes fstatvfs(SSH2SFTP.FileHandle handle) throws SSH2SFTP.SFTPException
handle - Handle of a file in the filesystemSSH2SFTP.SFTPExceptionpublic void hardlink(java.lang.String oldpath,
java.lang.String newpath)
throws SSH2SFTP.SFTPException
oldpath - Old pathnewpath - New pathSSH2SFTP.SFTPExceptionpublic SSH2SFTP.FileHandle opendir(java.lang.String path) throws SSH2SFTP.SFTPException
path - name of directory to openSSH2SFTP.SFTPExceptionpublic SSH2SFTP.FileAttributes[] readdir(SSH2SFTP.FileHandle handle) throws SSH2SFTP.SFTPException
opendir.handle - Handle identifying the remote directory.SSH2SFTP.SFTPExceptionpublic void remove(java.lang.String name)
throws SSH2SFTP.SFTPException
name - Name of file to remove.SSH2SFTP.SFTPExceptionpublic void rename(java.lang.String oldName,
java.lang.String newName)
throws SSH2SFTP.SFTPException
oldName - current name of file to rename.newName - desired new name of file.SSH2SFTP.SFTPExceptionpublic void posixRename(java.lang.String oldName,
java.lang.String newName)
throws SSH2SFTP.SFTPException
oldName - current name of file to rename.newName - desired new name of file.SSH2SFTP.SFTPExceptionpublic void mkdir(java.lang.String name,
SSH2SFTP.FileAttributes attrs)
throws SSH2SFTP.SFTPException
name - name of directory to create.attrs - Attributes to apply to the new directory.SSH2SFTP.SFTPExceptionpublic void rmdir(java.lang.String name)
throws SSH2SFTP.SFTPException
name - Name of directory to remove.SSH2SFTP.SFTPExceptionpublic java.lang.String readlink(java.lang.String path)
throws SSH2SFTP.SFTPException
path - name of link to readSSH2SFTP.SFTPExceptionpublic void symlink(java.lang.String linkpath,
java.lang.String targetpath)
throws SSH2SFTP.SFTPException
linkpath - name of link to createtargetpath - target of linkSSH2SFTP.SFTPExceptionpublic SSH2SFTP.FileAttributes realpath(java.lang.String nameIn) throws SSH2SFTP.SFTPException
..'.nameIn - Path to canonalize.FileAttributes object with the name
filled in.SSH2SFTP.SFTPExceptionpublic void packetReceived(SSH2SFTP.SFTPPacket pkt)
packetReceived in interface SSH2SFTP.Callbackpublic void readFailed(SSH2SFTP.SFTPException e)
readFailed in interface SSH2SFTP.Callback