diff --git a/WHATSNEW b/WHATSNEW index f17bf4b62..1c6e28c48 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -1,5 +1,11 @@ Changes from Ant 1.10.9 TO Ant 1.10.10 ====================================== +Fixed bugs: +----------- + + * SCP (with sftp=true) task would fail if fetching file located in root directory + Bugzilla Report 64742 + Changes from Ant 1.10.8 TO Ant 1.10.9 ===================================== diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java index 0ad089963..7e5edabf1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java @@ -134,9 +134,16 @@ public class ScpFromMessageBySftp extends ScpFromMessage { final String remoteFile, final File localFile) throws SftpException { String pwd = remoteFile; - if (remoteFile.lastIndexOf('/') != -1) { + final int lastIndexOfFileSeparator = remoteFile.lastIndexOf('/'); + if (lastIndexOfFileSeparator != -1) { if (remoteFile.length() > 1) { - pwd = remoteFile.substring(0, remoteFile.lastIndexOf('/')); + if (lastIndexOfFileSeparator == 0) { + // the file path is of the form "/foo....." i.e. the file separator + // occurs at the start (and only there). + pwd = "/"; + } else { + pwd = remoteFile.substring(0, lastIndexOfFileSeparator); + } } } channel.cd(pwd);