Index: SFTPRepository.java =================================================================== --- SFTPRepository.java (revision 603552) +++ SFTPRepository.java (working copy) @@ -20,6 +20,8 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -83,7 +85,9 @@ public Resource resolveResource(String path) { try { ChannelSftp c = getSftpChannel(path); - Collection r = c.ls(path); + + Collection r = c.ls(getRelativePath(path)); + if (r != null) { for (Iterator iter = r.iterator(); iter.hasNext();) { Object obj = iter.next(); @@ -99,6 +103,7 @@ Message.debug("reolving resource error: " + e.getMessage()); // silent fail, return unexisting resource } + return new BasicResource(path, false, 0, 0, false); } @@ -119,7 +124,12 @@ fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET); ChannelSftp c = getSftpChannel(source); try { - c.get(source, destination.getAbsolutePath(), new MyProgressMonitor()); + String relativePath = getRelativePath(source); + c.get(relativePath, destination.getAbsolutePath(), new MyProgressMonitor()); + } catch (URISyntaxException e) { + e.printStackTrace(); + IOException ex = new IOException(e.getMessage() + " The uri is in the wrong format. Please use scheme://user:pass@hostname/path/to/repository."); + ex.initCause(e); } catch (SftpException e) { e.printStackTrace(); IOException ex = new IOException("impossible to get " + source + " on " + getHost() @@ -132,14 +142,23 @@ public void put(File source, String destination, boolean overwrite) throws IOException { fireTransferInitiated(getResource(destination), TransferEvent.REQUEST_PUT); ChannelSftp c = getSftpChannel(destination); + try { - if (!overwrite && checkExistence(destination, c)) { + String path = getRelativePath(destination); + + if (!overwrite && checkExistence(path, c)) { throw new IOException("destination file exists and overwrite == true"); } - if (destination.indexOf('/') != -1) { - mkdirs(destination.substring(0, destination.lastIndexOf('/')), c); + + if (path.indexOf('/') != -1) { + mkdirs(path.substring(0, path.lastIndexOf('/')), c); } - c.put(source.getAbsolutePath(), destination, new MyProgressMonitor()); + + c.put(source.getAbsolutePath(), path, new MyProgressMonitor()); + } catch (URISyntaxException e) { + IOException ex = new IOException(e.getMessage() + " The uri is in the wrong format. Please use scheme://user:pass@hostname/path/to/repository."); + ex.initCause(e); + throw ex; } catch (SftpException e) { IOException ex = new IOException(e.getMessage()); ex.initCause(e); @@ -162,7 +181,23 @@ c.mkdir(directory); } } + + private String getRelativePath(String path) throws URISyntaxException { + String result = null; + URI uri = new URI(path); + result = uri.getPath(); + + if (result == null) { + throw new URISyntaxException(path, "Missing path in URI."); + } + + if (result.indexOf('/') == 0) { + result = '.' + result; + } + return result; + } + public List list(String parent) throws IOException { try { ChannelSftp c = getSftpChannel(parent);