| java.lang.Object | |
| ↳ | com.trilead.ssh2.SFTPv3Client |
A SFTPv3Client represents a SFTP (protocol version 3)
client connection tunnelled over a SSH-2 connection. This is a very simple
(synchronous) implementation.
Basically, most methods in this class map directly to one of the packet types described in draft-ietf-secsh-filexfer-02.txt.
Note: this is experimental code.
Error handling: the methods of this class throw IOExceptions. However, unless
there is catastrophic failure, exceptions of the type SFTPv3Client will
be thrown (a subclass of IOException). Therefore, you can implement more verbose
behavior by checking if a thrown exception if of this type. If yes, then you
can cast the exception and access detailed information about the failure.
Notes about file names, directory names and paths, copy-pasted from the specs:
If you are still not tired then please go on and read the comment for
setCharset(String).
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| charsetName | |||||||||||
| conn | |||||||||||
| debug | |||||||||||
| flag_closed | |||||||||||
| is | |||||||||||
| next_request_id | |||||||||||
| os | |||||||||||
| protocol_version | |||||||||||
| server_extensions | |||||||||||
| sess | |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
This constructor is deprecated.
this constructor (debug version) will disappear in the future,
use
SFTPv3Client(Connection) instead.
| |||||||||||
Create a SFTP v3 client.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Have the server canonicalize any given path name to an absolute path.
| |||||||||||
Close this SFTP session.
| |||||||||||
Close a file.
| |||||||||||
Create a file and open it for reading and writing.
| |||||||||||
Create a file and open it for reading and writing.
| |||||||||||
reate a file (truncate it if it already exists) and open it for reading and writing.
| |||||||||||
Create a file (truncate it if it already exists) and open it for reading and writing.
| |||||||||||
Create a symbolic link on the server.
| |||||||||||
Modify the attributes of a file.
| |||||||||||
Retrieve the file attributes of an open file.
| |||||||||||
The currently used charset for filename encoding/decoding.
| |||||||||||
Returns the negotiated SFTP protocol version between the client and the server.
| |||||||||||
List the contents of a directory.
| |||||||||||
Retrieve the file attributes of a file.
| |||||||||||
Create a new directory.
| |||||||||||
Move a file or directory.
| |||||||||||
Open a file for reading.
| |||||||||||
Open a file for reading and writing.
| |||||||||||
Read bytes from a file.
| |||||||||||
Read the target of a symbolic link.
| |||||||||||
Remove a file.
| |||||||||||
Remove an empty directory.
| |||||||||||
Set the charset used to convert between Java Unicode Strings and byte encodings
used by the server for paths and file names.
| |||||||||||
Modify the attributes of a file.
| |||||||||||
Retrieve the file attributes of a file.
| |||||||||||
Write bytes to a file.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
This constructor is deprecated.
this constructor (debug version) will disappear in the future,
use SFTPv3Client(Connection) instead.
Create a SFTP v3 client.
| conn | The underlying SSH-2 connection to be used. |
|---|---|
| debug |
| IOException | |
| IOException |
Create a SFTP v3 client.
| conn | The underlying SSH-2 connection to be used. |
|---|
| IOException |
|---|
Have the server canonicalize any given path name to an absolute path. This is useful for converting path names containing ".." components or relative pathnames without a leading slash into absolute paths.
| path | See the comment for the class for more details. |
|---|
| IOException |
|---|
Close this SFTP session. NEVER forget to call this method to free up
resources - even if you got an exception from one of the other methods.
Sometimes these other methods may throw an exception, saying that the
underlying channel is closed (this can happen, e.g., if the other server
sent a close message.) However, as long as you have not called the
close() method, you are likely wasting resources.
Create a file and open it for reading and writing.
Same as createFile(fileName, null).
| fileName | See the comment for the class for more details. |
|---|
| IOException |
|---|
Create a file and open it for reading and writing. You can specify the default attributes of the file (the server may or may not respect your wishes).
| fileName | See the comment for the class for more details. |
|---|---|
| attr | May be null to use server defaults. Probably only
the uid, gid and permissions
(remember the server may apply a umask) entries of the SFTPv3FileHandle
structure make sense. You need only to set those fields where you want
to override the server's defaults. |
| IOException |
|---|
reate a file (truncate it if it already exists) and open it for reading and writing. You can specify the default attributes of the file (the server may or may not respect your wishes).
| fileName | See the comment for the class for more details. |
|---|---|
| attr | May be null to use server defaults. Probably only
the uid, gid and permissions
(remember the server may apply a umask) entries of the SFTPv3FileHandle
structure make sense. You need only to set those fields where you want
to override the server's defaults. |
| IOException |
|---|
Create a file (truncate it if it already exists) and open it for reading and writing.
Same as createFileTruncate(fileName, null).
| fileName | See the comment for the class for more details. |
|---|
| IOException |
|---|
Create a symbolic link on the server. Creates a link "src" that points to "target".
| src | See the comment for the class for more details. |
|---|---|
| target | See the comment for the class for more details. |
| IOException |
|---|
Modify the attributes of a file. Used for operations such as changing the ownership, permissions or access times, as well as for truncating a file.
| handle | A SFTPv3FileHandle handle |
|---|---|
| attr | A SFTPv3FileAttributes object. Specifies the modifications to be made to the attributes of the file. Empty fields will be ignored. |
| IOException |
|---|
Retrieve the file attributes of an open file.
| handle | A SFTPv3FileHandle handle. |
|---|
| IOException |
|---|
The currently used charset for filename encoding/decoding.
null if the platform's default charset is being used)
Returns the negotiated SFTP protocol version between the client and the server.
List the contents of a directory.
| dirName | See the comment for the class for more details. |
|---|
SFTPv3DirectoryEntry objects.| IOException |
|---|
Retrieve the file attributes of a file. This method does NOT follow symbolic links on the server.
| path | See the comment for the class for more details. |
|---|
| IOException |
|---|
Create a new directory.
| dirName | See the comment for the class for more details. |
|---|---|
| posixPermissions | The permissions for this directory, e.g., "0700" (remember that this is octal noation). The server will likely apply a umask. |
| IOException |
|---|
Move a file or directory.
| oldPath | See the comment for the class for more details. |
|---|---|
| newPath | See the comment for the class for more details. |
| IOException |
|---|
Open a file for reading.
| fileName | See the comment for the class for more details. |
|---|
| IOException |
|---|
Open a file for reading and writing.
| fileName | See the comment for the class for more details. |
|---|
| IOException |
|---|
Read bytes from a file. No more than 32768 bytes may be read at once. Be aware that the semantics of read() are different than for Java streams.
len),
and return them.-1 is returned.
| handle | A SFTPv3FileHandle handle |
|---|---|
| fileOffset | Offset (in bytes) in the file |
| dst | The destination byte array |
| dstoff | Offset in the destination byte array |
| len | How many bytes to read, 0 < len <= 32768 bytes |
EOF| IOException |
|---|
Read the target of a symbolic link.
| path | See the comment for the class for more details. |
|---|
| IOException |
|---|
Remove a file.
| fileName | See the comment for the class for more details. |
|---|
| IOException |
|---|
Remove an empty directory.
| dirName | See the comment for the class for more details. |
|---|
| IOException |
|---|
Set the charset used to convert between Java Unicode Strings and byte encodings used by the server for paths and file names. Unfortunately, the SFTP v3 draft says NOTHING about such conversions (well, with the exception of error messages which have to be in UTF-8). Newer drafts specify to use UTF-8 for file names (if I remember correctly). However, a quick test using OpenSSH serving a EXT-3 filesystem has shown that UTF-8 seems to be a bad choice for SFTP v3 (tested with filenames containing german umlauts). "windows-1252" seems to work better for Europe. Luckily, "windows-1252" is the platform default in my case =).
If you don't set anything, then the platform default will be used (this is the default behavior).
| charset | The name of the charset to be used or null to use the platform's
default encoding. |
|---|
| IOException |
|---|
Modify the attributes of a file. Used for operations such as changing the ownership, permissions or access times, as well as for truncating a file.
| path | See the comment for the class for more details. |
|---|---|
| attr | A SFTPv3FileAttributes object. Specifies the modifications to be made to the attributes of the file. Empty fields will be ignored. |
| IOException |
|---|
Retrieve the file attributes of a file. This method follows symbolic links on the server.
| path | See the comment for the class for more details. |
|---|
| IOException |
|---|
Write bytes to a file. If len > 32768, then the write operation will
be split into multiple writes.
| handle | A SFTPv3FileHandle handle. |
|---|---|
| fileOffset | Offset (in bytes) in the file. |
| src | The source byte array. |
| srcoff | Offset in the source byte array. |
| len | How many bytes to write. |
| IOException |
|---|