|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mindbright.ssh2.SSH2SFTP
com.mindbright.ssh2.SSH2SFTPClient
Implements the client side of the sftp protocol. File reads and writes
can be either synchronous (blocking) or asynchronous
(non-blocking). Asynchronous operation is much faster but is more
complicated to use when the interface is used for reading
parts of files. In asynchronous mode 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.
Nested Class Summary |
Nested classes inherited from class com.mindbright.ssh2.SSH2SFTP |
SSH2SFTP.AsyncListener, SSH2SFTP.FileAttributes, SSH2SFTP.FileHandle, SSH2SFTP.SFTPAsyncAbortException, SSH2SFTP.SFTPDisconnectException, SSH2SFTP.SFTPEOFException, SSH2SFTP.SFTPException, SSH2SFTP.SFTPNoSuchFileException, SSH2SFTP.SFTPPacket, SSH2SFTP.SFTPPermissionDeniedException |
Field Summary |
Constructor Summary | |
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. |
Method Summary | |
void |
asyncWait(SSH2SFTP.FileHandle handle)
Wait for all outstanding asynchoronous 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.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. |
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. |
int |
readFully(SSH2SFTP.FileHandle handle,
java.io.OutputStream out)
Read the entire file on the server and store in a local stream. |
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. |
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SSH2SFTPClient(SSH2Connection connection, boolean isBlocking) throws SSH2SFTP.SFTPException
connection
- Connection to run over.isBlocking
- True if read and write operations should be
synchronous.public 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.Method Detail |
public void terminate()
public void restart() throws SSH2SFTP.SFTPException
SSH2SFTP.SFTPException
public 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.SFTPException
public void close(SSH2SFTP.FileHandle handle) throws SSH2SFTP.SFTPException
handle
- Handle identifying file.
SSH2SFTP.SFTPException
public void asyncWait(SSH2SFTP.FileHandle handle) throws SSH2SFTP.SFTPException
handle
- Handle identifying file.
SSH2SFTP.SFTPException
public 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 strean. 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.SFTPException
java.io.IOException
public 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.SFTPException
public 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.SFTPException
java.io.IOException
protected void writeInternal(SSH2SFTP.FileHandle handle, SSH2SFTP.SFTPPacket pkt, int len) throws SSH2SFTP.SFTPException
SSH2SFTP.SFTPException
public 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.SFTPException
public 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.SFTPException
java.io.IOException
public 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.SFTPException
java.io.IOException
public 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.SFTPException
java.io.IOException
public SSH2SFTP.FileAttributes lstat(java.lang.String name) throws SSH2SFTP.SFTPException
name
- Name of file to get attributes of.
SSH2SFTP.SFTPException
public SSH2SFTP.FileAttributes stat(java.lang.String name) throws SSH2SFTP.SFTPException
name
- Name of file to get attributes of.
SSH2SFTP.SFTPException
public SSH2SFTP.FileAttributes fstat(SSH2SFTP.FileHandle handle) throws SSH2SFTP.SFTPException
handle
- Handle identifying file.
SSH2SFTP.SFTPException
public 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.SFTPException
public void fsetstat(SSH2SFTP.FileHandle handle, SSH2SFTP.FileAttributes attrs) throws SSH2SFTP.SFTPException
handle
- Handle identifying the file.attrs
- Attributes to set.
SSH2SFTP.SFTPException
public SSH2SFTP.FileHandle opendir(java.lang.String path) throws SSH2SFTP.SFTPException
path
- name of directory to open
SSH2SFTP.SFTPException
public SSH2SFTP.FileAttributes[] readdir(SSH2SFTP.FileHandle handle) throws SSH2SFTP.SFTPException
opendir
.
handle
- Hande identifying the remote directory.
SSH2SFTP.SFTPException
public void remove(java.lang.String name) throws SSH2SFTP.SFTPException
name
- Name of file to remove.
SSH2SFTP.SFTPException
public 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.SFTPException
public 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.SFTPException
public void rmdir(java.lang.String name) throws SSH2SFTP.SFTPException
name
- Name of directory to remove.
SSH2SFTP.SFTPException
public SSH2SFTP.FileAttributes realpath(java.lang.String nameIn) throws SSH2SFTP.SFTPException
..
'.
nameIn
- Path to canonalize.
FileAttributes
object with the name and
lname fields filled in.
SSH2SFTP.SFTPException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |