You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by im...@apache.org on 2004/05/24 22:15:26 UTC
cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/sftp SftpFileObject.java SftpFileProvider.java
imario 2004/05/24 13:15:26
Modified: vfs/src/java/org/apache/commons/vfs Resources.properties
vfs/src/java/org/apache/commons/vfs/provider/sftp
SftpFileObject.java SftpFileProvider.java
Log:
add capability: getLastModificationTime
process the new configuration options setKnownHosts,setIdentities
Revision Changes Path
1.34 +2 -0 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- Resources.properties 20 May 2004 17:40:55 -0000 1.33
+++ Resources.properties 24 May 2004 20:15:26 -0000 1.34
@@ -191,6 +191,8 @@
vfs.provider.sftp/put-file.error=Write file contents failed with unknown error.
vfs.provider.sftp/get-file.error=Read file contents failed with unknown error.
vfs.provider.sftp/load-private-key.error=Could not load private key from "{0}".
+vfs.provider.sftp/config-sshdir.error=SSH-Folder "{0}" non existent or not a folder.
+vfs.provider.sftp/unknown-modtime.error=Last modification time not fetched.
# Ant tasks
vfs.tasks/sync.no-destination.error=No destination file or directory specified.
1.9 +15 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
Index: SftpFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SftpFileObject.java 10 May 2004 20:09:51 -0000 1.8
+++ SftpFileObject.java 24 May 2004 20:15:26 -0000 1.9
@@ -137,6 +137,15 @@
}
}
+ protected long doGetLastModifiedTime() throws Exception
+ {
+ if (attrs == null || (attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) == 0)
+ {
+ throw new FileSystemException("vfs.provider.sftp/unknown-modtime.error");
+ }
+ return attrs.getMTime() * 1000L;
+ }
+
/**
* Deletes the file.
*/
@@ -227,7 +236,7 @@
protected long doGetContentSize()
throws Exception
{
- if ((attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_SIZE) == 0)
+ if (attrs == null || (attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_SIZE) == 0)
{
throw new FileSystemException("vfs.provider.sftp/unknown-size.error");
}
@@ -243,12 +252,16 @@
final ChannelSftp channel = fileSystem.getChannel();
try
{
+ // return channel.get(getName().getPath());
+ // hmmm - using the in memory method is soooo much faster ...
+
// TODO - Don't read the entire file into memory. Use the
// stream-based methods on ChannelSftp once they work properly
final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
channel.get(getName().getPath(), outstr);
outstr.close();
return new ByteArrayInputStream(outstr.toByteArray());
+
}
finally
{
1.11 +78 -28 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/sftp/SftpFileProvider.java
Index: SftpFileProvider.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/sftp/SftpFileProvider.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- SftpFileProvider.java 19 May 2004 19:34:06 -0000 1.10
+++ SftpFileProvider.java 24 May 2004 20:15:26 -0000 1.11
@@ -50,14 +50,15 @@
Capability.LIST_CHILDREN,
Capability.READ_CONTENT,
Capability.URI,
- Capability.WRITE_CONTENT
+ Capability.WRITE_CONTENT,
+ Capability.GET_LAST_MODIFIED
}));
public final static String ATTR_USER_INFO = "UI";
private static final String SSH_DIR_NAME = ".ssh";
- private JSch jSch = new JSch();
+ // private JSch jSch = new JSch();
public SftpFileProvider()
{
@@ -67,9 +68,79 @@
/**
* Creates a {@link FileSystem}.
*/
- protected FileSystem doCreateFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions)
+ protected FileSystem doCreateFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions) throws FileSystemException
{
- return new SftpFileSystem((GenericFileName) rootName, this.getJSch(), fileSystemOptions);
+ JSch jsch = createJSch(fileSystemOptions);
+
+ return new SftpFileSystem((GenericFileName) rootName, jsch, fileSystemOptions);
+ }
+
+ private JSch createJSch(FileSystemOptions fileSystemOptions) throws FileSystemException
+ {
+ JSch jsch = new JSch();
+
+ File sshDir = null;
+
+ // new style - user passed
+ File knownHostsFile = SftpFileSystemConfigBuilder.getInstance().getKnownHosts(fileSystemOptions);
+ File[] identities = SftpFileSystemConfigBuilder.getInstance().getIdentities(fileSystemOptions);
+
+ if (knownHostsFile != null)
+ {
+ jsch.setKnownHosts(knownHostsFile.getAbsolutePath());
+ }
+ else
+ {
+ if (sshDir == null)
+ {
+ sshDir = this.findSshDir();
+ }
+ // Load the known hosts file
+ knownHostsFile = new File(sshDir, "known_hosts");
+ if (knownHostsFile.isFile() && knownHostsFile.canRead())
+ {
+ jsch.setKnownHosts(knownHostsFile.getAbsolutePath());
+ }
+ }
+
+ if (identities != null)
+ {
+ for (int iterIdentities = 0; iterIdentities < identities.length; iterIdentities++)
+ {
+ final File privateKeyFile = identities[iterIdentities];
+ try
+ {
+ jsch.addIdentity(privateKeyFile.getAbsolutePath());
+ }
+ catch (final JSchException e)
+ {
+ throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e);
+ }
+ }
+ }
+ else
+ {
+ if (sshDir == null)
+ {
+ sshDir = this.findSshDir();
+ }
+
+ // Load the private key (rsa-key only)
+ final File privateKeyFile = new File(sshDir, "id_rsa");
+ if (privateKeyFile.isFile() && privateKeyFile.canRead())
+ {
+ try
+ {
+ jsch.addIdentity(privateKeyFile.getAbsolutePath());
+ }
+ catch (final JSchException e)
+ {
+ throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e);
+ }
+ }
+ }
+
+ return jsch;
}
/**
@@ -128,39 +199,18 @@
*
* @return Returns the jSch.
*/
+ /*
private JSch getJSch()
{
return this.jSch;
}
+ */
/**
* Initialises the component.
*/
public void init() throws FileSystemException
{
- // Figure out where the ssh directory is
- File sshDir = this.findSshDir();
-
- // Load the known hosts file
- final File knownHostsFile = new File(sshDir, "known_hosts");
- if (knownHostsFile.isFile() && knownHostsFile.canRead())
- {
- this.getJSch().setKnownHosts(knownHostsFile.getAbsolutePath());
- }
-
- // Load the private key
- final File privateKeyFile = new File(sshDir, "id_rsa");
- if (privateKeyFile.isFile() && privateKeyFile.canRead())
- {
- try
- {
- this.getJSch().addIdentity(privateKeyFile.getAbsolutePath());
- }
- catch (final JSchException e)
- {
- throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e);
- }
- }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org