From fd126ea83074cffca634b5e6ef2ae80844ff7695 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 16 Jul 2008 09:32:52 +0000 Subject: [PATCH] Create remoteDir if needed, More meaningful error when exception occurs. PR 42781. Submitted by Eduard Wirch. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@677211 13f79535-47bb-0310-9956-ffa450edef68 --- CONTRIBUTORS | 1 + WHATSNEW | 3 ++ contributors.xml | 4 +++ .../optional/ssh/ScpToMessageBySftp.java | 29 ++++++++++++++----- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index f1ca99bc5..6a7f3343a 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -74,6 +74,7 @@ Don Brown Don Ferguson Don Jeffery Drew Sudell +Eduard Wirch Edwin Woudt Eli Tucker Emmanuel Bourg diff --git a/WHATSNEW b/WHATSNEW index 8d15c2e31..3c6e27d1b 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -104,6 +104,9 @@ Fixed bugs: * XmlLogger could lose messages if is used. Bugzilla Report 25734. + * creates remoteToDir if it doesn't exist. + Bugzilla Report 42781 + Other changes: -------------- diff --git a/contributors.xml b/contributors.xml index 46d612978..6cd2cc024 100644 --- a/contributors.xml +++ b/contributors.xml @@ -319,6 +319,10 @@ Drew Sudell + + Eduard + Wirch + Edwin Woudt 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 767b172f0..c94415978 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 @@ -153,24 +153,37 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { channel.connect(); try { + try { + channel.stat(remotePath); + } catch (SftpException e) { + if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { + // dir does not exist. + channel.mkdir(remotePath); + } else { + throw new JSchException("failed to access remote dir '" + + remotePath + "'", e); + } + } channel.cd(remotePath); } catch (SftpException e) { - JSchException schException = new JSchException("Could not CD to '" + remotePath + "' - " + e.toString()); - schException.initCause(e); - throw schException; + throw new JSchException("Could not CD to '" + remotePath + + "' - " + e.toString(), e); } + Directory current = null; try { for (Iterator i = directoryList.iterator(); i.hasNext();) { - Directory current = (Directory) i.next(); - if(getVerbose()) { + current = (Directory) i.next(); + if (getVerbose()) { log("Sending directory " + current); } sendDirectory(channel, current); } } catch (SftpException e) { - JSchException schException = new JSchException(e.toString()); - schException.initCause(e); - throw schException; + String msg = "Error sending directory"; + if (current != null && current.getDirectory() != null) { + msg += " '" + current.getDirectory().getName() + "'"; + } + throw new JSchException(msg, e); } } finally { if (channel != null) {