|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.mucommander.file.AbstractFile
com.mucommander.file.impl.sftp.SFTPFile
public class SFTPFile
SFTPFile provides access to files located on an SFTP server.
The associated FileURL scheme is FileProtocols.SFTP. The host part of the URL designates the
SFTP server. Credentials must be specified in the login and password parts as SFTP servers require a login and
password. The path separator is '/'.
Here are a few examples of valid SFTP URLs:
sftp://server/pathto/somefile
sftp://login:password@server/pathto/somefile
Internally, SFTPFile uses ConnectionPool to create SFTP connections as needed and allows them to be
reused by SFTPFile instances located on the same server, dealing with concurrency issues. Connections are
thus managed transparently and need not be manually managed.
Low-level SFTP implementation is provided by the J2SSH library distributed under the LGPL license.
ConnectionPool| Field Summary | |
|---|---|
static java.lang.String |
PRIVATE_KEY_PATH_PROPERTY_NAME
Name of the property that holds the path to a private key. |
| Fields inherited from class com.mucommander.file.AbstractFile |
|---|
DEFAULT_SEPARATOR, fileURL, IO_BUFFER_SIZE, MUST_HINT, MUST_NOT_HINT, SHOULD_HINT, SHOULD_NOT_HINT, windowsDriveRootPattern |
| Fields inherited from interface com.mucommander.file.PermissionTypes |
|---|
EXECUTE_PERMISSION, READ_PERMISSION, WRITE_PERMISSION |
| Fields inherited from interface com.mucommander.file.PermissionAccesses |
|---|
GROUP_ACCESS, OTHER_ACCESS, USER_ACCESS |
| Constructor Summary | |
|---|---|
SFTPFile(FileURL fileURL)
Creates a new instance of SFTPFile and initializes the SSH/SFTP connection to the server. |
|
| Method Summary | |
|---|---|
boolean |
canChangeDate()
Returns true if this file's date can be changed using AbstractFile.changeDate(long). |
boolean |
canGetGroup()
Returns true if this file implementation is able to return some information about file groups, not
necessarily for all files or this file in particular but at least for some of them. |
boolean |
canGetOwner()
Returns true if this file implementation is able to return some information about file owners, not
necessarily for all files or this file in particular but at least for some of them. |
boolean |
canRunProcess()
Returns true if it's possible to run processes on the underlying file system. |
boolean |
changeDate(long lastModified)
Changes last modified date and returns true if date was changed successfully, false
if the operation could not be completed, either because this method is not implemented for this file type, or
because of insufficient permissions or a low-level I/O error. |
boolean |
changePermission(int access,
int permission,
boolean enabled)
Changes the specified permission bit. |
boolean |
changePermissions(int permissions)
Changes this file's permissions to the specified permissions int and returns true if
the operation was successful, false if at least one of the file permissions could not be changed. |
ConnectionHandler |
createConnectionHandler(FileURL location)
|
void |
delete()
Deletes this file and this file only (does not recurse on folders). |
boolean |
exists()
Implementation note: for symlinks, returns the value of the link's target. |
java.lang.String |
getCanonicalPath()
Returns the canonical path to this file, resolving any symbolic links or '..' and '.' occurrences. |
PermissionBits |
getChangeablePermissions()
Returns a bit mask describing the permission bits that can be changed on this file when calling AbstractFile.changePermission(int, int, boolean) and AbstractFile.changePermissions(int). |
long |
getDate()
Implementation note: for symlinks, returns the date of the link's target. |
long |
getFreeSpace()
Returns the free space (in bytes) on the disk/volume where this file is, -1 if this information is
not available. |
java.lang.String |
getGroup()
Returns information about the group this file belongs to. |
java.io.InputStream |
getInputStream()
Returns an InputStream to read the contents of this file. |
java.io.InputStream |
getInputStream(long offset)
Returns an InputStream to read this file's contents, starting at the specified offset (in bytes). |
java.io.OutputStream |
getOutputStream(boolean append)
Returns an OuputStream to write the contents of this file, appending or overwriting the existing
contents. |
java.lang.String |
getOwner()
Returns information about the owner of this file. |
AbstractFile |
getParent()
Returns this file's parent, null if it doesn't have one. |
FilePermissions |
getPermissions()
Implementation note: for symlinks, returns the permissions of the link's target. |
RandomAccessInputStream |
getRandomAccessInputStream()
Returns a RandomAccessInputStream to read the contents of this file with random access. |
RandomAccessOutputStream |
getRandomAccessOutputStream()
Returns a RandomAccessOutputStream to write the contents of this file with random access. |
long |
getSize()
Implementation note: for symlinks, returns the size of the link's target. |
long |
getTotalSpace()
Returns the total space (in bytes) of the disk/volume where this file is, -1 if this information is not available. |
java.lang.Object |
getUnderlyingFileObject()
Returns a SFTPFile.SFTPFileAttributes instance corresponding to this file. |
boolean |
hasRandomAccessInputStream()
Returns true: getRandomAccessInputStream() is implemented. |
boolean |
hasRandomAccessOutputStream()
Returns false: getRandomAccessOutputStream() is not implemented and throws an
IOException. |
boolean |
isDirectory()
Implementation note: for symlinks, returns the value of the link's target. |
boolean |
isSymlink()
Implementation note: the value returned by this method will always be false if this file was
created by the public constructor. |
AbstractFile[] |
ls()
Returns the children files that this file contains. |
void |
mkdir()
Creates this file as a directory. |
boolean |
moveTo(AbstractFile destFile)
Overrides AbstractFile.moveTo(AbstractFile) to support server-to-server move if the destination file
uses SFTP and is located on the same host. |
AbstractProcess |
runProcess(java.lang.String[] tokens)
Creates a process executing the specified command tokens using this file as a working directory. |
static void |
setAttributeCachingPeriod(long period)
Sets the time period during which attributes values (e.g. |
void |
setParent(AbstractFile parent)
Sets this file's parent. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String PRIVATE_KEY_PATH_PROPERTY_NAME
| Constructor Detail |
|---|
public SFTPFile(FileURL fileURL)
throws java.io.IOException
java.io.IOException| Method Detail |
|---|
public static void setAttributeCachingPeriod(long period)
0 disables attributes caching.
This class ensures that the attributes changed remotely by one of its methods are always updated locally, even
with attributes caching enabled. To illustrate, after a call to mkdir(), isDirectory() will
return true, even if the attributes haven't been refreshed. The attributes will however not be
consistent if they have been changed by another SFTPFile or by another process, and will remain
inconsistent for up to period milliseconds.
period - time period during which attributes values are cached, in milliseconds. 0 disables attributes caching.public ConnectionHandler createConnectionHandler(FileURL location)
public boolean isSymlink()
false if this file was
created by the public constructor. If this file was created by the private constructor (by ls(),
the value will be accurate (true if this file is a symlink) but will never get updated.
See SFTPFile.SFTPFileAttributes for more information.
isSymlink in class AbstractFiletrue if this file is a symbolic linkpublic long getDate()
getDate in class AbstractFilepublic boolean canChangeDate()
AbstractFiletrue if this file's date can be changed using AbstractFile.changeDate(long). It's important
to note that a true return value doesn't mean that a call to AbstractFile.changeDate(long) will
necessarily succeed ; it could fail because of unsufficient permissions or simply because of a low-level I/O ;
but it should at least ensure that AbstractFile.changeDate(long) is implemented and has a chance of succeeding.
canChangeDate in class AbstractFiletrue if this file's date can be changed using AbstractFile.changeDate(long)public boolean changeDate(long lastModified)
AbstractFiletrue if date was changed successfully, false
if the operation could not be completed, either because this method is not implemented for this file type, or
because of insufficient permissions or a low-level I/O error.
changeDate in class AbstractFilelastModified - last modified date, in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)
true if date was changed successfully.public long getSize()
getSize in class AbstractFile
public AbstractFile getParent()
throws java.io.IOException
AbstractFilenull if it doesn't have one.
getParent in class AbstractFilenull if it doesn't have one
java.io.IOException - if the parent file could not be instanciatedpublic void setParent(AbstractFile parent)
AbstractFilenull can be specified if this file doesn't have a parent.
setParent in class AbstractFileparent - the new parent of this filepublic boolean exists()
exists in class AbstractFiletrue if this file existspublic FilePermissions getPermissions()
getPermissions in class AbstractFilepublic PermissionBits getChangeablePermissions()
AbstractFileAbstractFile.changePermission(int, int, boolean) and AbstractFile.changePermissions(int).
getChangeablePermissions in class AbstractFile
public boolean changePermission(int access,
int permission,
boolean enabled)
AbstractFileAbstractFile.getChangeablePermissions()), this method has no effect and false is returned.
changePermission in class AbstractFileaccess - see PermissionTypes for allowed valuespermission - see PermissionAccesses for allowed valuesenabled - true to enable the flag, false to disable it
AbstractFile.getChangeablePermissions()public java.lang.String getOwner()
AbstractFileAbstractFile implementation (cannot be retrieved or
the filesystem doesn't have any notion of owner) or not available for this particular file, null
will be returned.
getOwner in class AbstractFilepublic boolean canGetOwner()
AbstractFiletrue if this file implementation is able to return some information about file owners, not
necessarily for all files or this file in particular but at least for some of them. In other words, a
true return value doesn't mean that AbstractFile.getOwner() will necessarily return a non-null value,
but rather that there is a chance that it does.
canGetOwner in class AbstractFilepublic java.lang.String getGroup()
AbstractFileAbstractFile implementation (cannot be retrieved or
the filesystem doesn't have any notion of owner) or not available for this particular file, null
will be returned.
getGroup in class AbstractFilepublic boolean canGetGroup()
AbstractFiletrue if this file implementation is able to return some information about file groups, not
necessarily for all files or this file in particular but at least for some of them. In other words, a
true return value doesn't mean that AbstractFile.getGroup() will necessarily return a non-null value,
but rather that there is a chance that it does.
canGetGroup in class AbstractFilepublic boolean isDirectory()
isDirectory in class AbstractFiletrue if this file is a directory, false in any of the cases listed above
public java.io.InputStream getInputStream()
throws java.io.IOException
AbstractFileInputStream to read the contents of this file.
Throws an IOException in any of the following cases:
RandomAccessInputStream cannot be provided because the underlying file protocol doesn't have
random access support (see AbstractFile.hasRandomAccessInputStream()null.
getInputStream in class AbstractFileInputStream to read the contents of this file
java.io.IOException - in any of the cases listed above
public java.io.OutputStream getOutputStream(boolean append)
throws java.io.IOException
AbstractFileOuputStream to write the contents of this file, appending or overwriting the existing
contents. This file will be created as a zero-byte file if it does not yet exist.
Throws an IOException in any of the following cases:
append is specified but not supportednull.
getOutputStream in class AbstractFileappend - if true, data written to the OutputStream will be appended to the end of this file. If false,
any existing data this file contains will be discarded and overwritten.
OuputStream to write the contents of this file
java.io.IOException - in any of the cases listed abovepublic boolean hasRandomAccessInputStream()
true: getRandomAccessInputStream() is implemented.
hasRandomAccessInputStream in class AbstractFile
public RandomAccessInputStream getRandomAccessInputStream()
throws java.io.IOException
AbstractFileRandomAccessInputStream to read the contents of this file with random access.
Throws an IOException in any of the following cases:
RandomAccessInputStream cannot be provided because the underlying file protocol doesn't have
random access support (see AbstractFile.hasRandomAccessInputStream()null.
getRandomAccessInputStream in class AbstractFileRandomAccessInputStream to read the contents of this file with random access
java.io.IOException - in any of the cases listed abovepublic boolean hasRandomAccessOutputStream()
false: getRandomAccessOutputStream() is not implemented and throws an
IOException.
hasRandomAccessOutputStream in class AbstractFile
public RandomAccessOutputStream getRandomAccessOutputStream()
throws java.io.IOException
AbstractFileRandomAccessOutputStream to write the contents of this file with random access.
This file will be created as a zero-byte file if it does not yet exist.
Throws an IOException in any of the following cases:
RandomAccessOutputStream cannot be provided because the underlying file protocol doesn't have
random access support (see AbstractFile.hasRandomAccessOutputStream()null.
getRandomAccessOutputStream in class AbstractFileRandomAccessOutputStream to write the contents of this file with random access
java.io.IOException - in any of the cases listed above
public void delete()
throws java.io.IOException
AbstractFileIOException in any of the following cases:
delete in class AbstractFilejava.io.IOException - if this file does not exist or could not be deleted
public AbstractFile[] ls()
throws java.io.IOException
AbstractFileAbstractFile.isBrowsable() must return true.
This method may return a zero-length array if it has no children but may never return null.
ls in class AbstractFilejava.io.IOException - if this operation is not possible (file is not browsable) or if an error occurred.
public void mkdir()
throws java.io.IOException
AbstractFileIOException) if this file
already exists.
mkdir in class AbstractFilejava.io.IOException - if the directory could not be created, either because this file already exists or for any
other reason.public long getFreeSpace()
AbstractFile-1 if this information is
not available.
getFreeSpace in class AbstractFile-1 if this information is
not available.public long getTotalSpace()
AbstractFile
getTotalSpace in class AbstractFilepublic java.lang.Object getUnderlyingFileObject()
SFTPFile.SFTPFileAttributes instance corresponding to this file.
getUnderlyingFileObject in class AbstractFilenull if there
is nonepublic boolean canRunProcess()
AbstractFiletrue if it's possible to run processes on the underlying file system.
canRunProcess in class AbstractFiletrue if it's possible to run processes on the underlying file system, false otherwise.
public AbstractProcess runProcess(java.lang.String[] tokens)
throws java.io.IOException
AbstractFile
runProcess in class AbstractFiletokens - command and its arguments for the process to create.
java.io.IOException - thrown if an error occured while creating the process, if the current file is not a directory or if the operation is not supported.public boolean changePermissions(int permissions)
AbstractFiletrue if
the operation was successful, false if at least one of the file permissions could not be changed.
The permissions int should be constructed using the permission types and accesses defined in
PermissionTypes and PermissionAccesses.
Implementation note: the default implementation of this method calls sequentially AbstractFile.changePermission(int, int, boolean),
for each permission and access (that's a total 9 calls). This may affect performance on filesystems which need
to perform an I/O request to change each permission individually. In that case, and if the fileystem allows
to change all permissions at once, this method should be overridden.
changePermissions in class AbstractFilepermissions - new permissions for this file
public boolean moveTo(AbstractFile destFile)
throws FileTransferException
AbstractFile.moveTo(AbstractFile) to support server-to-server move if the destination file
uses SFTP and is located on the same host.
moveTo in class AbstractFiledestFile - the destination file to move this file to
FileTransferException - in any of the cases listed above, use FileTransferException.getReason() to
know the reason.
public java.io.InputStream getInputStream(long offset)
throws java.io.IOException
AbstractFileInputStream to read this file's contents, starting at the specified offset (in bytes).
A java.io.IOException is thrown if the file doesn't exist.
This method should be overridden whenever possible to provide a more efficient implementation as this
default implementation uses InputStream.skip(long) which, depending on the particular InputStream
implementation may just read bytes and discards them, which is very slow.
getInputStream in class AbstractFileoffset - the offset in bytes from the beginning of the file, must be >0
InputStream to read this file's contents, skipping the specified number of bytes
java.io.IOException - if this file cannot be read or is a folder.public java.lang.String getCanonicalPath()
AbstractFileThis implementation simply returns the value of AbstractFile.getAbsolutePath(), and thus should be overridden
if canonical path resolution is available.
getCanonicalPath in class AbstractFile
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard