You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wagon-commits@maven.apache.org by br...@apache.org on 2008/05/27 09:48:53 UTC
svn commit: r660417 - in
/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch:
ScpWagon.java SftpWagon.java
Author: brett
Date: Tue May 27 00:48:53 2008
New Revision: 660417
URL: http://svn.apache.org/viewvc?rev=660417&view=rev
Log:
[WAGON-179] implement getFileList and resourceExists for SFTP protocol
Modified:
maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/ScpWagon.java
maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/SftpWagon.java
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/ScpWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/ScpWagon.java?rev=660417&r1=660416&r2=660417&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/ScpWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/ScpWagon.java Tue May 27 00:48:53 2008
@@ -128,7 +128,7 @@
try
{
// exec 'scp -t -d rfile' remotely
- String command = "scp -t " + path;
+ String command = "scp -t \"" + path + "\"";
fireTransferDebug( "Executing command: " + command );
Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/SftpWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/SftpWagon.java?rev=660417&r1=660416&r2=660417&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/SftpWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/SftpWagon.java Tue May 27 00:48:53 2008
@@ -20,6 +20,10 @@
*/
import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
import org.apache.maven.wagon.PathUtils;
import org.apache.maven.wagon.ResourceDoesNotExistException;
@@ -222,10 +226,12 @@
dir = dir.substring( 1 );
}
+ ChannelSftp channel = null;
+
boolean bDownloaded = true;
try
{
- ChannelSftp channel = (ChannelSftp) session.openChannel( SFTP_CHANNEL );
+ channel = (ChannelSftp) session.openChannel( SFTP_CHANNEL );
channel.connect();
@@ -268,6 +274,13 @@
{
handleGetException( resource, e, destination );
}
+ finally
+ {
+ if ( channel != null )
+ {
+ channel.disconnect();
+ }
+ }
return bDownloaded;
}
@@ -422,4 +435,118 @@
putFile( channel, sourceFile, resource, permissions );
}
}
+
+ public List getFileList( String destinationDirectory )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ String filename = getResourceFilename( destinationDirectory );
+
+ String dir = getResourceDirectory( destinationDirectory );
+
+ // we already setuped the root directory. Ignore beginning /
+ if ( dir.length() > 0 && dir.charAt( 0 ) == PATH_SEPARATOR )
+ {
+ dir = dir.substring( 1 );
+ }
+
+ ChannelSftp channel = null;
+ try
+ {
+ channel = (ChannelSftp) session.openChannel( SFTP_CHANNEL );
+
+ channel.connect();
+
+ SftpATTRS attrs = changeToRepositoryDirectory( channel, dir, filename );
+ if ( ( attrs.getPermissions() & S_IFDIR ) == 0 )
+ {
+ throw new TransferFailedException( "Remote path is not a directory:" + dir );
+ }
+
+ Vector fileList = channel.ls( filename );
+ List files = new ArrayList( fileList.size() );
+ for ( Iterator i = fileList.iterator(); i.hasNext(); )
+ {
+ ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) i.next();
+
+ files.add( entry.getFilename() );
+ }
+ return files;
+ }
+ catch ( SftpException e )
+ {
+ String msg =
+ "Error occured while listing '" + destinationDirectory + "' " + "on remote repository: "
+ + getRepository().getUrl();
+
+ throw new TransferFailedException( msg, e );
+ }
+ catch ( JSchException e )
+ {
+ String msg =
+ "Error occured while listing '" + destinationDirectory + "' " + "on remote repository: "
+ + getRepository().getUrl();
+
+ throw new TransferFailedException( msg, e );
+ }
+ finally
+ {
+ if ( channel != null )
+ {
+ channel.disconnect();
+ }
+ }
+ }
+
+ public boolean resourceExists( String resourceName )
+ throws TransferFailedException, AuthorizationException
+ {
+ String filename = getResourceFilename( resourceName );
+
+ String dir = getResourceDirectory( resourceName );
+
+ // we already setuped the root directory. Ignore beginning /
+ if ( dir.length() > 0 && dir.charAt( 0 ) == PATH_SEPARATOR )
+ {
+ dir = dir.substring( 1 );
+ }
+
+ ChannelSftp channel = null;
+ try
+ {
+ channel = (ChannelSftp) session.openChannel( SFTP_CHANNEL );
+
+ channel.connect();
+
+ changeToRepositoryDirectory( channel, dir, filename );
+
+ return true;
+ }
+ catch ( ResourceDoesNotExistException e )
+ {
+ return false;
+ }
+ catch ( SftpException e )
+ {
+ String msg =
+ "Error occured while looking for '" + resourceName + "' " + "on remote repository: "
+ + getRepository().getUrl();
+
+ throw new TransferFailedException( msg, e );
+ }
+ catch ( JSchException e )
+ {
+ String msg =
+ "Error occured while looking for '" + resourceName + "' " + "on remote repository: "
+ + getRepository().getUrl();
+
+ throw new TransferFailedException( msg, e );
+ }
+ finally
+ {
+ if ( channel != null )
+ {
+ channel.disconnect();
+ }
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org