diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c649ae7a9..3a36ac656 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -162,6 +162,7 @@ Issa Gorissen Ivan Ivanov J Bleijenbergh Jack J. Woehr +Jaikiran Pai James Duncan Davidson Jan Cumps Jan Matèrne diff --git a/WHATSNEW b/WHATSNEW index b3a7a4ece..8e76f47db 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -8,9 +8,16 @@ Fixed bugs: value. Bugzilla Report 60767 + * bootstrapping Ant on Windows failed Bugzilla Report 61027 + * Bugzilla Reports 59648 and 43271 - Fixed the issue where the + SCP based tasks would try to change the permissions on the + parent directory of a transferred file, instead of changing it + on the transferred file itself. + + Other changes: -------------- diff --git a/contributors.xml b/contributors.xml index c73478cec..a0077b73e 100644 --- a/contributors.xml +++ b/contributors.xml @@ -673,6 +673,10 @@ J. Woehr + + Jaikiran + Pai + James Duncan diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java index dc8f2f15d..a1177c417 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java @@ -135,11 +135,9 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { try { sendFileToRemote(channel, localFile, remotePath); } catch (final SftpException e) { - final JSchException schException = new JSchException("Could not send '" + localFile + throw new JSchException("Could not send '" + localFile + "' to '" + remotePath + "' - " - + e.toString()); - schException.initCause(e); - throw schException; + + e.toString(), e); } } finally { if (channel != null) { @@ -247,7 +245,24 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { log("Sending: " + localFile.getName() + " : " + filesize); } channel.put(localFile.getAbsolutePath(), remotePath, monitor); - channel.chmod(getFileMode(), remotePath); + // set the fileMode on the transferred file. The "remotePath" can potentially be a directory + // into which the file got transferred, so we can't/shouldn't go ahead and try to change that directory's + // permissions. Instead we determine the path of the transferred file on remote. + final String transferredFileRemotePath; + if (channel.stat(remotePath).isDir()) { + // Note: It's correct to use "/" as the file separator without worrying about what the remote + // server's file separator is, since the SFTP spec expects "/" to be considered as file path + // separator. See section 6.2 "File Names" of the spec, which states: + // "This protocol represents file names as strings. File names are + // assumed to use the slash ('/') character as a directory separator." + transferredFileRemotePath = remotePath + "/" + localFile.getName(); + } else { + transferredFileRemotePath = remotePath; + } + if (this.getVerbose()) { + log("Setting file mode '" + Integer.toOctalString(getFileMode()) + "' on remote path " + transferredFileRemotePath); + } + channel.chmod(getFileMode(), transferredFileRemotePath); } finally { if (this.getVerbose()) { final long endTime = System.currentTimeMillis();