aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh')
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java272
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Directory.java196
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/LogListener.java30
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java236
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java519
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHSession.java333
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHUserInfo.java217
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java486
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java311
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java205
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java331
-rw-r--r--framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java277
12 files changed, 0 insertions, 3413 deletions
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java
deleted file mode 100644
index 9365e8cd..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.text.NumberFormat;
-
-import org.apache.tools.ant.BuildException;
-
-import com.jcraft.jsch.Channel;
-import com.jcraft.jsch.ChannelExec;
-import com.jcraft.jsch.ChannelSftp;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-import com.jcraft.jsch.SftpProgressMonitor;
-
-/**
- * Abstract class for ssh upload and download
- */
-public abstract class AbstractSshMessage {
- private static final double ONE_SECOND = 1000.0;
-
- private final Session session;
- private final boolean verbose;
- private LogListener listener = new LogListener() {
- public void log(final String message) {
- // do nothing;
- }
- };
-
- /**
- * Constructor for AbstractSshMessage
- * @param session the ssh session to use
- */
- public AbstractSshMessage(final Session session) {
- this(false, session);
- }
-
- /**
- * Constructor for AbstractSshMessage
- * @param verbose if true do verbose logging
- * @param session the ssh session to use
- * @since Ant 1.6.2
- */
- public AbstractSshMessage(final boolean verbose, final Session session) {
- this.verbose = verbose;
- this.session = session;
- }
-
- /**
- * Open an ssh channel.
- * @param command the command to use
- * @return the channel
- * @throws JSchException on error
- */
- protected Channel openExecChannel(final String command) throws JSchException {
- final ChannelExec channel = (ChannelExec) session.openChannel("exec");
- channel.setCommand(command);
-
- return channel;
- }
-
- /**
- * Open an ssh sftp channel.
- * @return the channel
- * @throws JSchException on error
- */
- protected ChannelSftp openSftpChannel() throws JSchException {
- final ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
-
- return channel;
- }
-
- /**
- * Send an ack.
- * @param out the output stream to use
- * @throws IOException on error
- */
- protected void sendAck(final OutputStream out) throws IOException {
- final byte[] buf = new byte[1];
- buf[0] = 0;
- out.write(buf);
- out.flush();
- }
-
- /**
- * Reads the response, throws a BuildException if the response
- * indicates an error.
- * @param in the input stream to use
- * @throws IOException on I/O error
- * @throws BuildException on other errors
- */
- protected void waitForAck(final InputStream in)
- throws IOException, BuildException {
- final int b = in.read();
-
- // b may be 0 for success,
- // 1 for error,
- // 2 for fatal error,
-
- if (b == -1) {
- // didn't receive any response
- throw new BuildException("No response from server");
- } else if (b != 0) {
- final StringBuffer sb = new StringBuffer();
-
- int c = in.read();
- while (c > 0 && c != '\n') {
- sb.append((char) c);
- c = in.read();
- }
-
- if (b == 1) {
- throw new BuildException("server indicated an error: "
- + sb.toString());
- } else if (b == 2) {
- throw new BuildException("server indicated a fatal error: "
- + sb.toString());
- } else {
- throw new BuildException("unknown response, code " + b
- + " message: " + sb.toString());
- }
- }
- }
-
- /**
- * Carry out the transfer.
- * @throws IOException on I/O errors
- * @throws JSchException on ssh errors
- */
- public abstract void execute() throws IOException, JSchException;
-
- /**
- * Set a log listener.
- * @param aListener the log listener
- */
- public void setLogListener(final LogListener aListener) {
- listener = aListener;
- }
-
- /**
- * Log a message to the log listener.
- * @param message the message to log
- */
- protected void log(final String message) {
- listener.log(message);
- }
-
- /**
- * Log transfer stats to the log listener.
- * @param timeStarted the time started
- * @param timeEnded the finishing time
- * @param totalLength the total length
- */
- protected void logStats(final long timeStarted,
- final long timeEnded,
- final long totalLength) {
- final double duration = (timeEnded - timeStarted) / ONE_SECOND;
- final NumberFormat format = NumberFormat.getNumberInstance();
- format.setMaximumFractionDigits(2);
- format.setMinimumFractionDigits(1);
- listener.log("File transfer time: " + format.format(duration)
- + " Average Rate: " + format.format(totalLength / duration)
- + " B/s");
- }
-
- /**
- * Is the verbose attribute set.
- * @return true if the verbose attribute is set
- * @since Ant 1.6.2
- */
- protected final boolean getVerbose() {
- return verbose;
- }
-
- /**
- * Track progress every 10% if 100kb < filesize < 1mb. For larger
- * files track progress for every percent transmitted.
- * @param filesize the size of the file been transmitted
- * @param totalLength the total transmission size
- * @param percentTransmitted the current percent transmitted
- * @return the percent that the file is of the total
- */
- protected final int trackProgress(final long filesize, final long totalLength,
- final int percentTransmitted) {
-
- // CheckStyle:MagicNumber OFF
- final int percent = (int) Math.round(Math.floor((totalLength
- / (double) filesize) * 100));
-
- if (percent > percentTransmitted) {
- if (filesize < 1048576) {
- if (percent % 10 == 0) {
- if (percent == 100) {
- System.out.println(" 100%");
- } else {
- System.out.print("*");
- }
- }
- } else {
- if (percent == 50) {
- System.out.println(" 50%");
- } else if (percent == 100) {
- System.out.println(" 100%");
- } else {
- System.out.print(".");
- }
- }
- }
- // CheckStyle:MagicNumber ON
-
- return percent;
- }
-
- private ProgressMonitor monitor = null;
-
- /**
- * Get the progress monitor.
- * @return the progress monitor.
- */
- protected SftpProgressMonitor getProgressMonitor() {
- if (monitor == null) {
- monitor = new ProgressMonitor();
- }
- return monitor;
- }
-
- private class ProgressMonitor implements SftpProgressMonitor {
- private long initFileSize = 0;
- private long totalLength = 0;
- private int percentTransmitted = 0;
-
- public void init(final int op, final String src, final String dest, final long max) {
- initFileSize = max;
- totalLength = 0;
- percentTransmitted = 0;
- }
-
- public boolean count(final long len) {
- totalLength += len;
- percentTransmitted = trackProgress(initFileSize,
- totalLength,
- percentTransmitted);
- return true;
- }
-
- public void end() {
- }
-
- public long getTotalLength() {
- return totalLength;
- }
- }
-}
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Directory.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Directory.java
deleted file mode 100644
index b5088a7d..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Directory.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-/**
- * A helper object for Scp representing a directory in a file system.
- */
-public class Directory {
-
- private File directory;
- private Set childDirectories;
- private ArrayList files;
- private Directory parent;
-
- /**
- * Constructor for a Directory.
- * @param directory a directory.
- */
- public Directory(File directory) {
- this(directory, null);
- }
-
- /**
- * Constructor for a Directory.
- * @param directory a directory
- * @param parent a parent Directory
- */
- public Directory(File directory , Directory parent) {
- this.parent = parent;
- this.childDirectories = new LinkedHashSet();
- this.files = new ArrayList();
- this.directory = directory;
- }
-
- /**
- * Add a directory to the child directories.
- * @param directory a Directory
- */
- public void addDirectory(Directory directory) {
- if (!childDirectories.contains(directory)) {
- childDirectories.add(directory);
- }
- }
-
- /**
- * Add a file to the list of files.
- * @param file a file to add
- */
- public void addFile(File file) {
- files.add(file);
- }
-
- /**
- * Get an iterator over the child Directories.
- * @return an iterator
- */
- public Iterator directoryIterator() {
- return childDirectories.iterator();
- }
-
- /**
- * Get an iterator over the files.
- * @return an iterator
- */
- public Iterator filesIterator() {
- return files.iterator();
- }
-
- /**
- * Get the parent Directory.
- * @return the parent Directory.
- */
- public Directory getParent() {
- return parent;
- }
-
- /**
- * Is this a root Directory?
- * @return true if there is no parent Directory
- */
- public boolean isRoot() {
- return parent == null;
- }
-
- /**
- * Get the directory file.
- * @return the directory file
- */
- public File getDirectory() {
- return directory;
- }
-
- /**
- * Get a child directory of this directory.
- * @param dir the directory to look for
- * @return the child directory, or null if not found
- */
- public Directory getChild(File dir) {
- for (Iterator i = childDirectories.iterator(); i.hasNext();) {
- Directory current = (Directory) i.next();
- if (current.getDirectory().equals(dir)) {
- return current;
- }
- }
- return null;
- }
-
- /**
- * The equality method.
- * This checks if the directory field is the same.
- * @param obj the object to compare to
- * @return true if this object has an equal directory field as the other object
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
-
- if (!(obj instanceof Directory)) {
- return false;
- }
-
- Directory d = (Directory) obj;
-
- return this.directory.equals(d.directory);
- }
-
- /**
- * The hashcode method.
- * @return the hash code of the directory field
- */
- @Override
- public int hashCode() {
- return directory.hashCode();
- }
-
- /**
- * Get the path components of this directory.
- * @return the path components as an array of strings.
- */
- public String[] getPath() {
- return getPath(directory.getAbsolutePath());
- }
-
- /**
- * Convert a file path to an array of path components.
- * This uses File.separator to split the file path string.
- * @param thePath the file path string to convert
- * @return an array of path components
- */
- public static String[] getPath(String thePath) {
- StringTokenizer tokenizer = new StringTokenizer(thePath,
- File.separator);
- String[] path = new String[ tokenizer.countTokens() ];
-
- int i = 0;
- while (tokenizer.hasMoreTokens()) {
- path[i] = tokenizer.nextToken();
- i++;
- }
-
- return path;
- }
-
- /**
- * Get the number of files in the files attribute.
- * @return the number of files
- */
- public int fileSize() {
- return files.size();
- }
-}
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/LogListener.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/LogListener.java
deleted file mode 100644
index 41209ceb..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/LogListener.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-/**
- * Interface for ssh log listeners to implement.
- */
-public interface LogListener {
- /**
- * Method for the loglistener to implement to receive log messages.
- * @param message the message to log
- */
- void log(String message);
-}
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java
deleted file mode 100644
index 68419a85..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-
-/**
- * Base class for Ant tasks using jsch.
- *
- * @since Ant 1.6
- */
-public abstract class SSHBase extends Task implements LogListener {
-
- /** Default listen port for SSH daemon */
- private static final int SSH_PORT = 22;
-
- private String host;
- private String knownHosts;
- private int port = SSH_PORT;
- private boolean failOnError = true;
- private boolean verbose;
- private final SSHUserInfo userInfo;
-
- /**
- * Constructor for SSHBase.
- */
- public SSHBase() {
- super();
- userInfo = new SSHUserInfo();
- }
-
- /**
- * Remote host, either DNS name or IP.
- *
- * @param host The new host value
- */
- public void setHost(final String host) {
- this.host = host;
- }
-
- /**
- * Get the host.
- * @return the host
- */
- public String getHost() {
- return host;
- }
-
- /**
- * Set the failonerror flag.
- * Default is true
- * @param failure if true throw a build exception when a failure occuries,
- * otherwise just log the failure and continue
- */
- public void setFailonerror(final boolean failure) {
- failOnError = failure;
- }
-
- /**
- * Get the failonerror flag.
- * @return the failonerror flag
- */
- public boolean getFailonerror() {
- return failOnError;
- }
-
- /**
- * Set the verbose flag.
- * @param verbose if true output more verbose logging
- * @since Ant 1.6.2
- */
- public void setVerbose(final boolean verbose) {
- this.verbose = verbose;
- }
-
- /**
- * Get the verbose flag.
- * @return the verbose flag
- * @since Ant 1.6.2
- */
- public boolean getVerbose() {
- return verbose;
- }
-
- /**
- * Username known to remote host.
- *
- * @param username The new username value
- */
- public void setUsername(final String username) {
- userInfo.setName(username);
- }
-
-
- /**
- * Sets the password for the user.
- *
- * @param password The new password value
- */
- public void setPassword(final String password) {
- userInfo.setPassword(password);
- }
-
- /**
- * Sets the keyfile for the user.
- *
- * @param keyfile The new keyfile value
- */
- public void setKeyfile(final String keyfile) {
- userInfo.setKeyfile(keyfile);
- }
-
- /**
- * Sets the passphrase for the users key.
- *
- * @param passphrase The new passphrase value
- */
- public void setPassphrase(final String passphrase) {
- userInfo.setPassphrase(passphrase);
- }
-
- /**
- * Sets the path to the file that has the identities of
- * all known hosts. This is used by SSH protocol to validate
- * the identity of the host. The default is
- * <i>${user.home}/.ssh/known_hosts</i>.
- *
- * @param knownHosts a path to the known hosts file.
- */
- public void setKnownhosts(final String knownHosts) {
- this.knownHosts = knownHosts;
- }
-
- /**
- * Setting this to true trusts hosts whose identity is unknown.
- *
- * @param yesOrNo if true trust the identity of unknown hosts.
- */
- public void setTrust(final boolean yesOrNo) {
- userInfo.setTrust(yesOrNo);
- }
-
- /**
- * Changes the port used to connect to the remote host.
- *
- * @param port port number of remote host.
- */
- public void setPort(final int port) {
- this.port = port;
- }
-
- /**
- * Get the port attribute.
- * @return the port
- */
- public int getPort() {
- return port;
- }
-
- /**
- * Initialize the task.
- * This initializizs the known hosts and sets the default port.
- * @throws BuildException on error
- */
- public void init() throws BuildException {
- super.init();
- this.knownHosts = System.getProperty("user.home") + "/.ssh/known_hosts";
- this.port = SSH_PORT;
- }
-
- /**
- * Open an ssh session.
- * @return the opened session
- * @throws JSchException on error
- */
- protected Session openSession() throws JSchException {
- final JSch jsch = new JSch();
- final SSHBase base = this;
- if (verbose) {
- JSch.setLogger(new com.jcraft.jsch.Logger(){
- public boolean isEnabled(final int level){
- return true;
- }
- public void log(final int level, final String message){
- base.log(message, Project.MSG_INFO);
- }
- });
- }
- if (null != userInfo.getKeyfile()) {
- jsch.addIdentity(userInfo.getKeyfile());
- }
-
- if (!userInfo.getTrust() && knownHosts != null) {
- log("Using known hosts: " + knownHosts, Project.MSG_DEBUG);
- jsch.setKnownHosts(knownHosts);
- }
-
- final Session session = jsch.getSession(userInfo.getName(), host, port);
- session.setConfig("PreferredAuthentications",
- "publickey,keyboard-interactive,password");
- session.setUserInfo(userInfo);
- log("Connecting to " + host + ":" + port);
- session.connect();
- return session;
- }
-
- /**
- * Get the user information.
- * @return the user information
- */
- protected SSHUserInfo getUserInfo() {
- return userInfo;
- }
-}
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
deleted file mode 100644
index a04dfefa..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
+++ /dev/null
@@ -1,519 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.StringReader;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.types.Resource;
-import org.apache.tools.ant.types.resources.FileResource;
-import org.apache.tools.ant.util.FileUtils;
-import org.apache.tools.ant.util.KeepAliveInputStream;
-import org.apache.tools.ant.util.KeepAliveOutputStream;
-import org.apache.tools.ant.util.TeeOutputStream;
-
-import com.jcraft.jsch.ChannelExec;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-
-/**
- * Executes a command on a remote machine via ssh.
- * @since Ant 1.6 (created February 2, 2003)
- */
-public class SSHExec extends SSHBase {
-
- private static final int BUFFER_SIZE = 8192;
- private static final int RETRY_INTERVAL = 500;
-
- /** the command to execute via ssh */
- private String command = null;
-
- /** units are milliseconds, default is 0=infinite */
- private long maxwait = 0;
-
- /** for waiting for the command to finish */
- private Thread thread = null;
-
- private String outputProperty = null; // like <exec>
- private String errorProperty = null;
- private String resultProperty = null;
- private File outputFile = null; // like <exec>
- private File errorFile = null;
- private String inputProperty = null;
- private String inputString = null; // like <exec>
- private File inputFile = null; // like <exec>
- private boolean append = false; // like <exec>
- private boolean appenderr = false;
- private boolean usePty = false;
- private boolean useSystemIn = false;
-
- private Resource commandResource = null;
-
- private static final String TIMEOUT_MESSAGE =
- "Timeout period exceeded, connection dropped.";
-
- /**
- * To suppress writing logs to System.out
- */
- private boolean suppressSystemOut = false;
-
- /**
- * To suppress writing logs to System.err
- */
- private boolean suppressSystemErr = false;
-
- /**
- * Constructor for SSHExecTask.
- */
- public SSHExec() {
- super();
- }
-
- /**
- * Sets the command to execute on the remote host.
- *
- * @param command The new command value
- */
- public void setCommand(final String command) {
- this.command = command;
- }
-
- /**
- * Sets a commandResource from a file
- * @param f the value to use.
- * @since Ant 1.7.1
- */
- public void setCommandResource(final String f) {
- this.commandResource = new FileResource(new File(f));
- }
-
- /**
- * The connection can be dropped after a specified number of
- * milliseconds. This is sometimes useful when a connection may be
- * flaky. Default is 0, which means &quot;wait forever&quot;.
- *
- * @param timeout The new timeout value in seconds
- */
- public void setTimeout(final long timeout) {
- maxwait = timeout;
- }
-
- /**
- * If used, stores the output of the command to the given file.
- *
- * @param output The file to write to.
- */
- public void setOutput(final File output) {
- outputFile = output;
- }
-
- /**
- * If used, stores the erroutput of the command to the given file.
- *
- * @param output The file to write to.
- * @since Apache Ant 1.9.4
- */
- public void setErrorOutput(final File output) {
- errorFile = output;
- }
-
- /**
- * If used, the content of the file is piped to the remote command
- *
- * @param input The file which provides the input data for the remote command
- *
- * @since Ant 1.8.0
- */
- public void setInput(final File input) {
- inputFile = input;
- }
-
- /**
- * If used, the content of the property is piped to the remote command
- *
- * @param inputProperty The property which contains the input data
- * for the remote command.
- *
- * @since Ant 1.8.0
- */
- public void setInputProperty(final String inputProperty) {
- this.inputProperty = inputProperty;
- }
-
- /**
- * If used, the string is piped to the remote command.
- *
- * @param inputString the input data for the remote command.
- *
- * @since Ant 1.8.3
- */
- public void setInputString(final String inputString) {
- this.inputString = inputString;
- }
-
- /**
- * Determines if the output is appended to the file given in
- * <code>setOutput</code>. Default is false, that is, overwrite
- * the file.
- *
- * @param append True to append to an existing file, false to overwrite.
- */
- public void setAppend(final boolean append) {
- this.append = append;
- }
-
- /**
- * Determines if the output is appended to the file given in
- * <code>setErrorOutput</code>. Default is false, that is, overwrite
- * the file.
- *
- * @param appenderr True to append to an existing file, false to overwrite.
- * @since Apache Ant 1.9.4
- */
- public void setErrAppend(final boolean appenderr) {
- this.appenderr = appenderr;
- }
-
- /**
- * If set, the output of the command will be stored in the given property.
- *
- * @param property The name of the property in which the command output
- * will be stored.
- */
- public void setOutputproperty(final String property) {
- outputProperty = property;
- }
-
- /**
- * If set, the erroroutput of the command will be stored in the given property.
- *
- * @param property The name of the property in which the command erroroutput
- * will be stored.
- * @since Apache Ant 1.9.4
- */
- public void setErrorproperty (final String property) {
- errorProperty = property;
- }
-
- /**
- * If set, the exitcode of the command will be stored in the given property.
- *
- * @param property The name of the property in which the exitcode
- * will be stored.
- * @since Apache Ant 1.9.4
- */
- public void setResultproperty(final String property) {
- resultProperty = property;
- }
-
- /**
- * Whether a pseudo-tty should be allocated.
- * @since Apache Ant 1.8.3
- */
- public void setUsePty(final boolean b) {
- usePty = b;
- }
-
- /**
- * If set, input will be taken from System.in
- *
- * @param useSystemIn True to use System.in as InputStream, false otherwise
- * @since Apache Ant 1.9.4
- */
- public void setUseSystemIn(final boolean useSystemIn) {
- this.useSystemIn = useSystemIn;
- }
-
- /**
- * If suppressSystemOut is <code>true</code>, output will not be sent to System.out<br/>
- * If suppressSystemOut is <code>false</code>, normal behavior
- * @since Ant 1.9.0
- */
- public void setSuppressSystemOut(final boolean suppressSystemOut) {
- this.suppressSystemOut = suppressSystemOut;
- }
-
- /**
- * If suppressSystemErr is <code>true</code>, output will not be sent to System.err<br/>
- * If suppressSystemErr is <code>false</code>, normal behavior
- * @since Ant 1.9.4
- */
- public void setSuppressSystemErr(final boolean suppressSystemErr) {
- this.suppressSystemErr = suppressSystemErr;
- }
-
- /**
- * Execute the command on the remote host.
- *
- * @exception BuildException Most likely a network error or bad parameter.
- */
- @Override
- public void execute() throws BuildException {
-
- if (getHost() == null) {
- throw new BuildException("Host is required.");
- }
- if (getUserInfo().getName() == null) {
- throw new BuildException("Username is required.");
- }
- if (getUserInfo().getKeyfile() == null
- && getUserInfo().getPassword() == null) {
- throw new BuildException("Password or Keyfile is required.");
- }
- if (command == null && commandResource == null) {
- throw new BuildException("Command or commandResource is required.");
- }
-
- final int numberOfInputs = (inputFile != null ? 1 : 0)
- + (inputProperty != null ? 1 : 0)
- + (inputString != null ? 1 : 0);
- if (numberOfInputs > 1) {
- throw new BuildException("You can't specify more than one of"
- + " inputFile, inputProperty and"
- + " inputString.");
- }
- if (inputFile != null && !inputFile.exists()) {
- throw new BuildException("The input file "
- + inputFile.getAbsolutePath()
- + " does not exist.");
- }
-
- Session session = null;
- final StringBuffer output = new StringBuffer();
- try {
- session = openSession();
- /* called once */
- if (command != null) {
- log("cmd : " + command, Project.MSG_INFO);
- executeCommand(session, command, output);
- } else { // read command resource and execute for each command
- try {
- final BufferedReader br = new BufferedReader(
- new InputStreamReader(commandResource.getInputStream()));
- String cmd;
- while ((cmd = br.readLine()) != null) {
- log("cmd : " + cmd, Project.MSG_INFO);
- output.append(cmd).append(" : ");
- executeCommand(session, cmd, output);
- output.append("\n");
- }
- FileUtils.close(br);
- } catch (final IOException e) {
- if (getFailonerror()) {
- throw new BuildException(e);
- } else {
- log("Caught exception: " + e.getMessage(),
- Project.MSG_ERR);
- }
- }
- }
- } catch (final JSchException e) {
- if (getFailonerror()) {
- throw new BuildException(e);
- } else {
- log("Caught exception: " + e.getMessage(), Project.MSG_ERR);
- }
- } finally {
- if (outputProperty != null) {
- getProject().setNewProperty(outputProperty, output.toString());
- }
- if (session != null && session.isConnected()) {
- session.disconnect();
- }
- }
- }
-
- private void executeCommand(final Session session, final String cmd, final StringBuffer sb)
- throws BuildException {
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
- final ByteArrayOutputStream errout = new ByteArrayOutputStream();
- final OutputStream teeErr = suppressSystemErr ? errout : new TeeOutputStream(errout, KeepAliveOutputStream.wrapSystemErr());
- final OutputStream tee = suppressSystemOut ? out : new TeeOutputStream(out, KeepAliveOutputStream.wrapSystemOut());
-
- InputStream istream = null;
- if (inputFile != null) {
- try {
- istream = new FileInputStream(inputFile);
- } catch (final IOException e) {
- // because we checked the existence before, this one
- // shouldn't happen What if the file exists, but there
- // are no read permissions?
- log("Failed to read " + inputFile + " because of: "
- + e.getMessage(), Project.MSG_WARN);
- }
- }
- if (inputProperty != null) {
- final String inputData = getProject().getProperty(inputProperty);
- if (inputData != null) {
- istream = new ByteArrayInputStream(inputData.getBytes());
- }
- }
- if (inputString != null) {
- istream = new ByteArrayInputStream(inputString.getBytes());
- }
-
- if (useSystemIn) {
- istream = KeepAliveInputStream.wrapSystemIn();
- }
-
- try {
- final ChannelExec channel;
- session.setTimeout((int) maxwait);
- /* execute the command */
- channel = (ChannelExec) session.openChannel("exec");
- channel.setCommand(cmd);
- channel.setOutputStream(tee);
- channel.setExtOutputStream(tee);
- channel.setErrStream(teeErr);
- if (istream != null) {
- channel.setInputStream(istream);
- }
- channel.setPty(usePty);
- channel.connect();
- // wait for it to finish
- thread =
- new Thread() {
- @Override
- public void run() {
- while (!channel.isClosed()) {
- if (thread == null) {
- return;
- }
- try {
- sleep(RETRY_INTERVAL);
- } catch (final Exception e) {
- // ignored
- }
- }
- }
- };
-
- thread.start();
- thread.join(maxwait);
-
- if (thread.isAlive()) {
- // ran out of time
- thread = null;
- if (getFailonerror()) {
- throw new BuildException(TIMEOUT_MESSAGE);
- } else {
- log(TIMEOUT_MESSAGE, Project.MSG_ERR);
- }
- } else {
- // stdout to outputFile
- if (outputFile != null) {
- writeToFile(out.toString(), append, outputFile);
- }
- // set errorProperty
- if (errorProperty != null) {
- getProject().setNewProperty(errorProperty, errout.toString());
- }
- // stderr to errorFile
- if (errorFile != null) {
- writeToFile(errout.toString(), appenderr, errorFile);
- }
- // this is the wrong test if the remote OS is OpenVMS,
- // but there doesn't seem to be a way to detect it.
- final int ec = channel.getExitStatus();
- // set resultproperty
- if (resultProperty != null) {
- getProject().setNewProperty(resultProperty, Integer.toString(ec));
- }
- if (ec != 0) {
- final String msg = "Remote command failed with exit status " + ec;
- if (getFailonerror()) {
- throw new BuildException(msg);
- } else {
- log(msg, Project.MSG_ERR);
- }
- }
- }
- } catch (final BuildException e) {
- throw e;
- } catch (final JSchException e) {
- if (e.getMessage().indexOf("session is down") >= 0) {
- if (getFailonerror()) {
- throw new BuildException(TIMEOUT_MESSAGE, e);
- } else {
- log(TIMEOUT_MESSAGE, Project.MSG_ERR);
- }
- } else {
- if (getFailonerror()) {
- throw new BuildException(e);
- } else {
- log("Caught exception: " + e.getMessage(),
- Project.MSG_ERR);
- }
- }
- } catch (final Exception e) {
- if (getFailonerror()) {
- throw new BuildException(e);
- } else {
- log("Caught exception: " + e.getMessage(), Project.MSG_ERR);
- }
- } finally {
- sb.append(out.toString());
- FileUtils.close(istream);
- }
- }
-
- /**
- * Writes a string to a file. If destination file exists, it may be
- * overwritten depending on the "append" value.
- *
- * @param from string to write
- * @param to file to write to
- * @param append if true, append to existing file, else overwrite
- * @exception Exception most likely an IOException
- */
- private void writeToFile(final String from, final boolean append, final File to)
- throws IOException {
- FileWriter out = null;
- try {
- out = new FileWriter(to.getAbsolutePath(), append);
- final StringReader in = new StringReader(from);
- final char[] buffer = new char[BUFFER_SIZE];
- int bytesRead;
- while (true) {
- bytesRead = in.read(buffer);
- if (bytesRead == -1) {
- break;
- }
- out.write(buffer, 0, bytesRead);
- }
- out.flush();
- } finally {
- if (out != null) {
- out.close();
- }
- }
- }
-
-}
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHSession.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHSession.java
deleted file mode 100644
index e9f26757..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHSession.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.Vector;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.TaskContainer;
-
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-
-
-/**
- * Establishes an ssh session with a remote machine, optionally
- * establishing port forwarding, then executes any nested task(s)
- * before closing the session.
- * @since Ant 1.8.0
- */
-public class SSHSession extends SSHBase {
-
- /** units are milliseconds, default is 0=infinite */
- private long maxwait = 0;
-
- private final Vector localTunnels = new Vector();
- private final Set localPortsUsed = new TreeSet();
- private final Vector remoteTunnels = new Vector();
- private final Set remotePortsUsed = new TreeSet();
- private NestedSequential nestedSequential = null;
-
- private static final String TIMEOUT_MESSAGE =
- "Timeout period exceeded, connection dropped.";
-
-
- /** Optional Vector holding the nested tasks */
- private final Vector nestedTasks = new Vector();
-
- /**
- * Add a nested task to Sequential.
- * <p>
- * @param nestedTask Nested task to execute Sequential
- * <p>
- */
- public void addTask(final Task nestedTask) {
- nestedTasks.addElement(nestedTask);
- }
-
- /**
- * The connection can be dropped after a specified number of
- * milliseconds. This is sometimes useful when a connection may be
- * flaky. Default is 0, which means &quot;wait forever&quot;.
- *
- * @param timeout The new timeout value in seconds
- */
- public void setTimeout(final long timeout) {
- maxwait = timeout;
- }
-
- /**
- * Changes the comma-delimited list of local tunnels to establish
- * on the connection.
- *
- * @param tunnels a comma-delimited list of lport:rhost:rport
- * tunnel specifications
- */
- public void setLocaltunnels(final String tunnels) {
- final String[] specs = tunnels.split(", ");
- for (int i = 0; i < specs.length; i++) {
- if (specs[i].length() > 0) {
- final String[] spec = specs[i].split(":", 3);
- final int lport = Integer.parseInt(spec[0]);
- final String rhost = spec[1];
- final int rport = Integer.parseInt(spec[2]);
- final LocalTunnel tunnel = createLocalTunnel();
- tunnel.setLPort(lport);
- tunnel.setRHost(rhost);
- tunnel.setRPort(rport);
- }
- }
- }
-
- /**
- * Changes the comma-delimited list of remote tunnels to establish
- * on the connection.
- *
- * @param tunnels a comma-delimited list of rport:lhost:lport
- * tunnel specifications
- */
- public void setRemotetunnels(final String tunnels) {
- final String[] specs = tunnels.split(", ");
- for (int i = 0; i < specs.length; i++) {
- if (specs[i].length() > 0) {
- final String[] spec = specs[i].split(":", 3);
- final int rport = Integer.parseInt(spec[0]);
- final String lhost = spec[1];
- final int lport = Integer.parseInt(spec[2]);
- final RemoteTunnel tunnel = createRemoteTunnel();
- tunnel.setRPort(rport);
- tunnel.setLHost(lhost);
- tunnel.setLPort(lport);
- }
- }
- }
-
-
- /**
- * Establish the ssh session and execute all nestedTasks
- *
- * @exception BuildException if one of the nested tasks fails, or
- * network error or bad parameter.
- */
- @Override
- public void execute() throws BuildException {
- if (getHost() == null) {
- throw new BuildException("Host is required.");
- }
- if (getUserInfo().getName() == null) {
- throw new BuildException("Username is required.");
- }
- if (getUserInfo().getKeyfile() == null
- && getUserInfo().getPassword() == null) {
- throw new BuildException("Password or Keyfile is required.");
- }
- if (nestedSequential == null) {
- throw new BuildException("Missing sequential element.");
- }
-
-
- Session session = null;
- try {
- // establish the session
- session = openSession();
- session.setTimeout((int) maxwait);
-
- for (final Iterator i = localTunnels.iterator(); i.hasNext();) {
- final LocalTunnel tunnel = (LocalTunnel) i.next();
- session.setPortForwardingL(tunnel.getLPort(),
- tunnel.getRHost(),
- tunnel.getRPort());
- }
-
- for (final Iterator i = remoteTunnels.iterator(); i.hasNext();) {
- final RemoteTunnel tunnel = (RemoteTunnel) i.next();
- session.setPortForwardingR(tunnel.getRPort(),
- tunnel.getLHost(),
- tunnel.getLPort());
- }
-
- for (final Iterator i = nestedSequential.getNested().iterator();
- i.hasNext();) {
- final Task nestedTask = (Task) i.next();
- nestedTask.perform();
- }
- // completed successfully
-
- } catch (final JSchException e) {
- if (e.getMessage().indexOf("session is down") >= 0) {
- if (getFailonerror()) {
- throw new BuildException(TIMEOUT_MESSAGE, e);
- } else {
- log(TIMEOUT_MESSAGE, Project.MSG_ERR);
- }
- } else {
- if (getFailonerror()) {
- throw new BuildException(e);
- } else {
- log("Caught exception: " + e.getMessage(),
- Project.MSG_ERR);
- }
- }
- } catch (final BuildException e) {
- // avoid wrapping it into yet another BuildException further down
- throw e;
- } catch (final Exception e) {
- if (getFailonerror()) {
- throw new BuildException(e);
- } else {
- log("Caught exception: " + e.getMessage(), Project.MSG_ERR);
- }
- } finally {
- if (session != null && session.isConnected()) {
- session.disconnect();
- }
- }
- }
-
- public LocalTunnel createLocalTunnel() {
- final LocalTunnel tunnel = new LocalTunnel();
- localTunnels.add(tunnel);
- return tunnel;
- }
-
- public RemoteTunnel createRemoteTunnel() {
- final RemoteTunnel tunnel = new RemoteTunnel();
- remoteTunnels.add(tunnel);
- return tunnel;
- }
-
- public class LocalTunnel {
- public LocalTunnel() {}
-
- int lport = 0;
- String rhost = null;
- int rport = 0;
- public void setLPort(final int lport) {
- final Integer portKey = new Integer(lport);
- if (localPortsUsed.contains(portKey)) {
- throw new BuildException("Multiple local tunnels defined to"
- + " use same local port " + lport);
- }
- localPortsUsed.add(portKey);
- this.lport = lport;
- }
- public void setRHost(final String rhost) { this.rhost = rhost; }
- public void setRPort(final int rport) { this.rport = rport; }
- public int getLPort() {
- if (lport == 0) {
- throw new BuildException("lport is required for LocalTunnel.");
- }
- return lport;
- }
- public String getRHost() {
- if (rhost == null) {
- throw new BuildException("rhost is required for LocalTunnel.");
- }
- return rhost;
- }
- public int getRPort() {
- if (rport == 0) {
- throw new BuildException("rport is required for LocalTunnel.");
- }
- return rport;
- }
- }
-
- public class RemoteTunnel {
- public RemoteTunnel() {}
-
- int lport = 0;
- String lhost = null;
- int rport = 0;
- public void setLPort(final int lport) { this.lport = lport; }
- public void setLHost(final String lhost) { this.lhost = lhost; }
- public void setRPort(final int rport) {
- final Integer portKey = new Integer(rport);
- if (remotePortsUsed.contains(portKey)) {
- throw new BuildException("Multiple remote tunnels defined to"
- + " use same remote port " + rport);
- }
- remotePortsUsed.add(portKey);
- this.rport = rport;
- }
- public int getLPort() {
- if (lport == 0) {
- throw new BuildException("lport is required for RemoteTunnel.");
- }
- return lport;
- }
- public String getLHost() {
- if (lhost == null) {
- throw new BuildException("lhost is required for RemoteTunnel.");
- }
- return lhost;
- }
- public int getRPort() {
- if (rport == 0) {
- throw new BuildException("rport is required for RemoteTunnel.");
- }
- return rport;
- }
- }
-
- /**
- * This is the sequential nested element of the macrodef.
- *
- * @return a sequential element to be configured.
- */
- public NestedSequential createSequential() {
- if (this.nestedSequential != null) {
- throw new BuildException("Only one sequential allowed");
- }
- this.nestedSequential = new NestedSequential();
- return this.nestedSequential;
- }
-
- /**
- * The class corresponding to the sequential nested element.
- * This is a simple task container.
- */
- public static class NestedSequential implements TaskContainer {
- private final List<Task> nested = new ArrayList<Task>();
-
- /**
- * Add a task or type to the container.
- *
- * @param task an unknown element.
- */
- public void addTask(final Task task) {
- nested.add(task);
- }
-
- /**
- * @return the list of unknown elements
- */
- public List<Task> getNested() {
- return nested;
- }
- }
-
-}
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHUserInfo.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHUserInfo.java
deleted file mode 100644
index 54e70293..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHUserInfo.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import com.jcraft.jsch.UIKeyboardInteractive;
-import com.jcraft.jsch.UserInfo;
-
-
-/**
- * Class containing information on an SSH user.
- */
-public class SSHUserInfo implements UserInfo, UIKeyboardInteractive {
-
- private String name;
- private String password = null;
- private String keyfile;
- private String passphrase = null;
- private boolean trustAllCertificates;
-
- /** Constructor for SSHUserInfo. */
- public SSHUserInfo() {
- super();
- this.trustAllCertificates = false;
- }
-
- /**
- * Constructor for SSHUserInfo.
- * @param password the user's password
- * @param trustAllCertificates if true trust hosts whose identity is unknown
- */
- public SSHUserInfo(String password, boolean trustAllCertificates) {
- super();
- this.password = password;
- this.trustAllCertificates = trustAllCertificates;
- }
-
- /**
- * Gets the user name.
- * @return the user name
- */
- public String getName() {
- return name;
- }
-
- /**
- * Gets the pass phrase of the user.
- * @param message a message
- * @return the passphrase
- */
- public String getPassphrase(String message) {
- return passphrase;
- }
-
- /**
- * Gets the user's password.
- * @return the user's password
- */
- public String getPassword() {
- return password;
- }
-
- /**
- * Prompts a string.
- * @param str the string
- * @return whether the string was prompted
- */
- public boolean prompt(String str) {
- return false;
- }
-
- /**
- * Indicates whether a retry was done.
- * @return whether a retry was done
- */
- public boolean retry() {
- return false;
- }
-
- /**
- * Sets the name.
- * @param name The name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * Sets the passphrase.
- * @param passphrase The passphrase to set
- */
- public void setPassphrase(String passphrase) {
- this.passphrase = passphrase;
- }
-
- /**
- * Sets the password.
- * @param password The password to set
- */
- public void setPassword(String password) {
- this.password = password;
- }
-
- /**
- * Sets the trust.
- * @param trust whether to trust or not.
- */
- public void setTrust(boolean trust) {
- this.trustAllCertificates = trust;
- }
-
- /**
- * @return whether to trust or not.
- */
- public boolean getTrust() {
- return this.trustAllCertificates;
- }
-
- /**
- * Returns the passphrase.
- * @return String
- */
- public String getPassphrase() {
- return passphrase;
- }
-
- /**
- * Returns the keyfile.
- * @return String
- */
- public String getKeyfile() {
- return keyfile;
- }
-
- /**
- * Sets the keyfile.
- * @param keyfile The keyfile to set
- */
- public void setKeyfile(String keyfile) {
- this.keyfile = keyfile;
- }
-
- /**
- * Implement the UserInfo interface.
- * @param message ignored
- * @return true always
- */
- public boolean promptPassphrase(String message) {
- return true;
- }
-
- /**
- * Implement the UserInfo interface.
- * @param passwordPrompt ignored
- * @return true the first time this is called, false otherwise
- */
- public boolean promptPassword(String passwordPrompt) {
- return true;
- }
-
- /**
- * Implement the UserInfo interface.
- * @param message ignored
- * @return the value of trustAllCertificates
- */
- public boolean promptYesNo(String message) {
- return trustAllCertificates;
- }
-
-//why do we do nothing?
- /**
- * Implement the UserInfo interface (noop).
- * @param message ignored
- */
- public void showMessage(String message) {
- //log(message, Project.MSG_DEBUG);
- }
-
- /**
- * Implementation of UIKeyboardInteractive#promptKeyboardInteractive.
- * @param destination not used.
- * @param name not used.
- * @param instruction not used.
- * @param prompt the method checks if this is one in length.
- * @param echo the method checks if the first element is false.
- * @return the password in an size one array if there is a password
- * and if the prompt and echo checks pass.
- */
- public String[] promptKeyboardInteractive(String destination,
- String name,
- String instruction,
- String[] prompt,
- boolean[] echo) {
- if (prompt.length != 1 || echo[0] || this.password == null) {
- return null;
- }
- String[] response = new String[1];
- response[0] = this.password;
- return response;
- }
-
-}
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java
deleted file mode 100644
index 46e2ac64..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.types.FileSet;
-
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-
-/**
- * Ant task for sending files to remote machine over ssh/scp.
- *
- * @since Ant 1.6
- */
-public class Scp extends SSHBase {
-
- private static final String[] FROM_ATTRS = {
- "file", "localfile", "remotefile" };
-
- private static final String[] TO_ATTRS = {
- "todir", "localtodir", "remotetodir", "localtofile", "remotetofile" };
-
- private String fromUri;
- private String toUri;
- private boolean preserveLastModified = false;
- private List fileSets = null;
- private boolean isFromRemote, isToRemote;
- private boolean isSftp = false;
- private Integer fileMode, dirMode;
-
- /**
- * Sets the file to be transferred. This can either be a remote
- * file or a local file. Remote files take the form:<br>
- * <i>user:password@host:/directory/path/file.example</i><br>
- * Files to transfer can also include a wildcard to include all
- * files in a remote directory. For example:<br>
- * <i>user:password@host:/directory/path/*</i><br>
- * @param aFromUri a string representing the file to transfer.
- */
- public void setFile(final String aFromUri) {
- setFromUri(aFromUri);
- this.isFromRemote = isRemoteUri(this.fromUri);
- }
-
- /**
- * Sets the location where files will be transferred to.
- * This can either be a remote directory or a local directory.
- * Remote directories take the form of:<br>
- * <i>user:password@host:/directory/path/</i><br>
- * This parameter is required.
-
- * @param aToUri a string representing the target of the copy.
- */
- public void setTodir(final String aToUri) {
- setToUri(aToUri);
- this.isToRemote = isRemoteUri(this.toUri);
- }
-
- /**
- * Similar to {@link #setFile setFile} but explicitly states that
- * the file is a local file. This is the only way to specify a
- * local file with a @ character.
- * @param aFromUri a string representing the source of the copy.
- * @since Ant 1.6.2
- */
- public void setLocalFile(final String aFromUri) {
- setFromUri(aFromUri);
- this.isFromRemote = false;
- }
-
- /**
- * Similar to {@link #setFile setFile} but explicitly states that
- * the file is a remote file.
- * @param aFromUri a string representing the source of the copy.
- * @since Ant 1.6.2
- */
- public void setRemoteFile(final String aFromUri) {
- validateRemoteUri("remoteFile", aFromUri);
- setFromUri(aFromUri);
- this.isFromRemote = true;
- }
-
- /**
- * Similar to {@link #setTodir setTodir} but explicitly states
- * that the directory is a local. This is the only way to specify
- * a local directory with a @ character.
- * @param aToUri a string representing the target of the copy.
- * @since Ant 1.6.2
- */
- public void setLocalTodir(final String aToUri) {
- setToUri(aToUri);
- this.isToRemote = false;
- }
-
- /**
- * Sets flag to determine if file timestamp from
- * remote system is to be preserved during copy.
- * @since Ant 1.8.0
- */
- public void setPreservelastmodified(final boolean yesOrNo) {
- this.preserveLastModified = yesOrNo;
- }
-
- /**
- * Similar to {@link #setTodir setTodir} but explicitly states
- * that the directory is a remote.
- * @param aToUri a string representing the target of the copy.
- * @since Ant 1.6.2
- */
- public void setRemoteTodir(final String aToUri) {
- validateRemoteUri("remoteToDir", aToUri);
- setToUri(aToUri);
- this.isToRemote = true;
- }
-
- private static void validateRemoteUri(final String type, final String aToUri) {
- if (!isRemoteUri(aToUri)) {
- throw new BuildException(type + " '" + aToUri + "' is invalid. "
- + "The 'remoteToDir' attribute must "
- + "have syntax like the "
- + "following: user:password@host:/path"
- + " - the :password part is optional");
- }
- }
-
- /**
- * Changes the file name to the given name while receiving it,
- * only useful if receiving a single file.
- * @param aToUri a string representing the target of the copy.
- * @since Ant 1.6.2
- */
- public void setLocalTofile(final String aToUri) {
- setToUri(aToUri);
- this.isToRemote = false;
- }
-
- /**
- * Changes the file name to the given name while sending it,
- * only useful if sending a single file.
- * @param aToUri a string representing the target of the copy.
- * @since Ant 1.6.2
- */
- public void setRemoteTofile(final String aToUri) {
- validateRemoteUri("remoteToFile", aToUri);
- setToUri(aToUri);
- this.isToRemote = true;
- }
-
- /**
- * Setting this to true to use sftp protocol.
- *
- * @param yesOrNo if true sftp protocol will be used.
- */
- public void setSftp(final boolean yesOrNo) {
- isSftp = yesOrNo;
- }
-
- /**
- * Set the file mode, defaults to "644".
- * @since Ant 1.9.5
- */
- public void setFileMode(String fileMode) {
- this.fileMode = Integer.parseInt(fileMode, 8);
- }
-
- /**
- * Set the dir mode, defaults to "755".
- * @since Ant 1.9.5
- */
- public void setDirMode(String dirMode) {
- this.dirMode = Integer.parseInt(dirMode, 8);
- }
-
- /**
- * Adds a FileSet transfer to remote host. NOTE: Either
- * addFileSet() or setFile() are required. But, not both.
- *
- * @param set FileSet to send to remote host.
- */
- public void addFileset(final FileSet set) {
- if (fileSets == null) {
- fileSets = new LinkedList();
- }
- fileSets.add(set);
- }
-
- /**
- * Initialize this task.
- * @throws BuildException on error
- */
- @Override
- public void init() throws BuildException {
- super.init();
- this.toUri = null;
- this.fromUri = null;
- this.fileSets = null;
- }
-
- /**
- * Execute this task.
- * @throws BuildException on error
- */
- @Override
- public void execute() throws BuildException {
- if (toUri == null) {
- throw exactlyOne(TO_ATTRS);
- }
- if (fromUri == null && fileSets == null) {
- throw exactlyOne(FROM_ATTRS, "one or more nested filesets");
- }
- try {
- if (isFromRemote && !isToRemote) {
- download(fromUri, toUri);
- } else if (!isFromRemote && isToRemote) {
- if (fileSets != null) {
- upload(fileSets, toUri);
- } else {
- upload(fromUri, toUri);
- }
- } else if (isFromRemote && isToRemote) {
- throw new BuildException(
- "Copying from a remote server to a remote server is not supported.");
- } else {
- throw new BuildException("'todir' and 'file' attributes "
- + "must have syntax like the following: "
- + "user:password@host:/path");
- }
- } catch (final Exception e) {
- if (getFailonerror()) {
- if(e instanceof BuildException) {
- final BuildException be = (BuildException) e;
- if(be.getLocation() == null) {
- be.setLocation(getLocation());
- }
- throw be;
- } else {
- throw new BuildException(e);
- }
- } else {
- log("Caught exception: " + e.getMessage(), Project.MSG_ERR);
- }
- }
- }
-
- private void download(final String fromSshUri, final String toPath)
- throws JSchException, IOException {
- final String file = parseUri(fromSshUri);
-
- Session session = null;
- try {
- session = openSession();
- ScpFromMessage message = null;
- if (!isSftp) {
- message =
- new ScpFromMessage(getVerbose(), session, file,
- getProject().resolveFile(toPath),
- fromSshUri.endsWith("*"),
- preserveLastModified);
- } else {
- message =
- new ScpFromMessageBySftp(getVerbose(), session, file,
- getProject().resolveFile(toPath),
- fromSshUri.endsWith("*"),
- preserveLastModified);
- }
- log("Receiving file: " + file);
- message.setLogListener(this);
- message.execute();
- } finally {
- if (session != null) {
- session.disconnect();
- }
- }
- }
-
- private void upload(final List fileSet, final String toSshUri)
- throws IOException, JSchException {
- final String file = parseUri(toSshUri);
-
- Session session = null;
- try {
- final List list = new ArrayList(fileSet.size());
- for (final Iterator i = fileSet.iterator(); i.hasNext();) {
- final FileSet set = (FileSet) i.next();
- final Directory d = createDirectory(set);
- if (d != null) {
- list.add(d);
- }
- }
- if (!list.isEmpty()) {
- session = openSession();
- ScpToMessage message = null;
- if (!isSftp) {
- message = new ScpToMessage(getVerbose(), session,
- list, file);
- } else {
- message = new ScpToMessageBySftp(getVerbose(), session,
- list, file);
- }
- message.setLogListener(this);
- if (fileMode != null) {
- message.setFileMode(fileMode.intValue());
- }
- if (dirMode != null) {
- message.setDirMode(dirMode.intValue());
- }
- message.execute();
- }
- } finally {
- if (session != null) {
- session.disconnect();
- }
- }
- }
-
- private void upload(final String fromPath, final String toSshUri)
- throws IOException, JSchException {
- final String file = parseUri(toSshUri);
-
- Session session = null;
- try {
- session = openSession();
- ScpToMessage message = null;
- if (!isSftp) {
- message =
- new ScpToMessage(getVerbose(), session,
- getProject().resolveFile(fromPath), file);
- } else {
- message =
- new ScpToMessageBySftp(getVerbose(), session,
- getProject().resolveFile(fromPath),
- file);
- }
- message.setLogListener(this);
- if (fileMode != null) {
- message.setFileMode(fileMode.intValue());
- }
- if (dirMode != null) {
- message.setDirMode(dirMode.intValue());
- }
- message.execute();
- } finally {
- if (session != null) {
- session.disconnect();
- }
- }
- }
-
- private String parseUri(final String uri) {
-
- int indexOfAt = uri.indexOf('@');
- final int indexOfColon = uri.indexOf(':');
-
- if (indexOfColon > -1 && indexOfColon < indexOfAt) {
- // user:password@host:/path notation
- // everything upto the last @ before the last : is considered
- // password. (so if the path contains an @ and a : it will not work)
- int indexOfCurrentAt = indexOfAt;
- final int indexOfLastColon = uri.lastIndexOf(':');
- while (indexOfCurrentAt > -1 && indexOfCurrentAt < indexOfLastColon)
- {
- indexOfAt = indexOfCurrentAt;
- indexOfCurrentAt = uri.indexOf('@', indexOfCurrentAt + 1);
- }
- setUsername(uri.substring(0, indexOfColon));
- setPassword(uri.substring(indexOfColon + 1, indexOfAt));
- } else if (indexOfAt > -1) {
- // no password, will require keyfile
- setUsername(uri.substring(0, indexOfAt));
- } else {
- throw new BuildException("no username was given. Can't authenticate.");
- }
-
- if (getUserInfo().getPassword() == null
- && getUserInfo().getKeyfile() == null) {
- throw new BuildException("neither password nor keyfile for user "
- + getUserInfo().getName() + " has been "
- + "given. Can't authenticate.");
- }
-
- final int indexOfPath = uri.indexOf(':', indexOfAt + 1);
- if (indexOfPath == -1) {
- throw new BuildException("no remote path in " + uri);
- }
-
- setHost(uri.substring(indexOfAt + 1, indexOfPath));
- String remotePath = uri.substring(indexOfPath + 1);
- if (remotePath.equals("")) {
- remotePath = ".";
- }
- return remotePath;
- }
-
- private static boolean isRemoteUri(final String uri) {
- boolean isRemote = true;
- final int indexOfAt = uri.indexOf('@');
- if (indexOfAt < 0) {
- isRemote = false;
- }
- return isRemote;
- }
-
- private Directory createDirectory(final FileSet set) {
- final DirectoryScanner scanner = set.getDirectoryScanner(getProject());
- Directory root = new Directory(scanner.getBasedir());
- final String[] files = scanner.getIncludedFiles();
- if (files.length != 0) {
- for (int j = 0; j < files.length; j++) {
- final String[] path = Directory.getPath(files[j]);
- Directory current = root;
- File currentParent = scanner.getBasedir();
- for (int i = 0; i < path.length; i++) {
- final File file = new File(currentParent, path[i]);
- if (file.isDirectory()) {
- current.addDirectory(new Directory(file));
- current = current.getChild(file);
- currentParent = current.getDirectory();
- } else if (file.isFile()) {
- current.addFile(file);
- }
- }
- }
- } else {
- // skip
- root = null;
- }
- return root;
- }
-
- private void setFromUri(final String fromUri) {
- if (this.fromUri != null) {
- throw exactlyOne(FROM_ATTRS);
- }
- this.fromUri = fromUri;
- }
-
- private void setToUri(final String toUri) {
- if (this.toUri != null) {
- throw exactlyOne(TO_ATTRS);
- }
- this.toUri = toUri;
- }
-
- private BuildException exactlyOne(final String[] attrs) {
- return exactlyOne(attrs, null);
- }
-
- private BuildException exactlyOne(final String[] attrs, final String alt) {
- final StringBuffer buf = new StringBuffer("Exactly one of ").append(
- '[').append(attrs[0]);
- for (int i = 1; i < attrs.length; i++) {
- buf.append('|').append(attrs[i]);
- }
- buf.append(']');
- if (alt != null) {
- buf.append(" or ").append(alt);
- }
- return new BuildException(buf.append(" is required.").toString());
- }
-}
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java
deleted file mode 100644
index b6d47379..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import java.io.ByteArrayOutputStream;
-import java.io.EOFException;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.apache.tools.ant.util.FileUtils;
-
-import com.jcraft.jsch.Channel;
-import com.jcraft.jsch.ChannelSftp;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-import com.jcraft.jsch.SftpATTRS;
-import com.jcraft.jsch.SftpException;
-
-/**
- * A helper object representing an scp download.
- */
-public class ScpFromMessage extends AbstractSshMessage {
-
- private static final int HUNDRED_KILOBYTES = 102400;
- private static final byte LINE_FEED = 0x0a;
- private static final int BUFFER_SIZE = 100*1024;
-
- private String remoteFile;
- private File localFile;
- private boolean isRecursive = false;
- private boolean preserveLastModified = false;
-
- /**
- * Constructor for ScpFromMessage
- * @param session the ssh session to use
- */
- public ScpFromMessage(final Session session) {
- super(session);
- }
-
- /**
- * Constructor for ScpFromMessage
- * @param verbose if true do verbose logging
- * @param session the ssh session to use
- * @since Ant 1.7
- */
- public ScpFromMessage(final boolean verbose, final Session session) {
- super(verbose, session);
- }
-
- /**
- * Constructor for ScpFromMessage.
- * @param verbose if true log extra information
- * @param session the Scp session to use
- * @param aRemoteFile the remote file name
- * @param aLocalFile the local file
- * @param recursive if true use recursion (-r option to scp)
- * @since Ant 1.6.2
- */
- public ScpFromMessage(final boolean verbose,
- final Session session,
- final String aRemoteFile,
- final File aLocalFile,
- final boolean recursive) {
- this(false, session, aRemoteFile, aLocalFile, recursive, false);
- }
-
- /**
- * Constructor for ScpFromMessage.
- * @param session the Scp session to use
- * @param aRemoteFile the remote file name
- * @param aLocalFile the local file
- * @param recursive if true use recursion (-r option to scp)
- */
- public ScpFromMessage(final Session session,
- final String aRemoteFile,
- final File aLocalFile,
- final boolean recursive) {
- this(false, session, aRemoteFile, aLocalFile, recursive);
- }
-
- /**
- * Constructor for ScpFromMessage.
- * @param verbose if true log extra information
- * @param session the Scp session to use
- * @param aRemoteFile the remote file name
- * @param aLocalFile the local file
- * @param recursive if true use recursion (-r option to scp)
- * @param preserveLastModified whether to preserve file
- * modification times
- * @since Ant 1.8.0
- */
- public ScpFromMessage(final boolean verbose,
- final Session session,
- final String aRemoteFile,
- final File aLocalFile,
- final boolean recursive,
- final boolean preserveLastModified) {
- super(verbose, session);
- this.remoteFile = aRemoteFile;
- this.localFile = aLocalFile;
- this.isRecursive = recursive;
- this.preserveLastModified = preserveLastModified;
- }
-
- /**
- * Carry out the transfer.
- * @throws IOException on i/o errors
- * @throws JSchException on errors detected by scp
- */
- public void execute() throws IOException, JSchException {
- String command = "scp -f ";
- if (isRecursive) {
- command += "-r ";
- }
- command += remoteFile;
- final Channel channel = openExecChannel(command);
- try {
- // get I/O streams for remote scp
- final OutputStream out = channel.getOutputStream();
- final InputStream in = channel.getInputStream();
-
- channel.connect();
-
- sendAck(out);
- startRemoteCpProtocol(in, out, localFile);
- } finally {
- if (channel != null) {
- channel.disconnect();
- }
- }
- log("done\n");
- }
-
- protected boolean getPreserveLastModified() {
- return preserveLastModified;
- }
-
- private void startRemoteCpProtocol(final InputStream in,
- final OutputStream out,
- final File localFile)
- throws IOException, JSchException {
- File startFile = localFile;
- while (true) {
- // C0644 filesize filename - header for a regular file
- // T time 0 time 0\n - present if perserve time.
- // D directory - this is the header for a directory.
- final ByteArrayOutputStream stream = new ByteArrayOutputStream();
- while (true) {
- final int read = in.read();
- if (read < 0) {
- return;
- }
- if ((byte) read == LINE_FEED) {
- break;
- }
- stream.write(read);
- }
- final String serverResponse = stream.toString("UTF-8");
- if (serverResponse.charAt(0) == 'C') {
- parseAndFetchFile(serverResponse, startFile, out, in);
- } else if (serverResponse.charAt(0) == 'D') {
- startFile = parseAndCreateDirectory(serverResponse,
- startFile);
- sendAck(out);
- } else if (serverResponse.charAt(0) == 'E') {
- startFile = startFile.getParentFile();
- sendAck(out);
- } else if (serverResponse.charAt(0) == '\01'
- || serverResponse.charAt(0) == '\02') {
- // this indicates an error.
- throw new IOException(serverResponse.substring(1));
- }
- }
- }
-
- private File parseAndCreateDirectory(final String serverResponse,
- final File localFile) {
- int start = serverResponse.indexOf(" ");
- // appears that the next token is not used and it's zero.
- start = serverResponse.indexOf(" ", start + 1);
- final String directoryName = serverResponse.substring(start + 1);
- if (localFile.isDirectory()) {
- final File dir = new File(localFile, directoryName);
- dir.mkdir();
- log("Creating: " + dir);
- return dir;
- }
- return null;
- }
-
- private void parseAndFetchFile(final String serverResponse,
- final File localFile,
- final OutputStream out,
- final InputStream in)
- throws IOException, JSchException {
- int start = 0;
- int end = serverResponse.indexOf(" ", start + 1);
- start = end + 1;
- end = serverResponse.indexOf(" ", start + 1);
- final long filesize = Long.parseLong(serverResponse.substring(start, end));
- final String filename = serverResponse.substring(end + 1);
- log("Receiving: " + filename + " : " + filesize);
- final File transferFile = (localFile.isDirectory())
- ? new File(localFile, filename)
- : localFile;
- fetchFile(transferFile, filesize, out, in);
- waitForAck(in);
- sendAck(out);
- }
-
- private void fetchFile(final File localFile,
- long filesize,
- final OutputStream out,
- final InputStream in)
- throws IOException, JSchException {
- final byte[] buf = new byte[BUFFER_SIZE];
- sendAck(out);
-
- // read a content of lfile
- final FileOutputStream fos = new FileOutputStream(localFile);
- int length;
- long totalLength = 0;
- final long startTime = System.currentTimeMillis();
-
- // only track progress for files larger than 100kb in verbose mode
- final boolean trackProgress = getVerbose() && filesize > HUNDRED_KILOBYTES;
- // since filesize keeps on decreasing we have to store the
- // initial filesize
- final long initFilesize = filesize;
- int percentTransmitted = 0;
-
- try {
- while (true) {
- length = in.read(buf, 0,
- (BUFFER_SIZE < filesize) ? BUFFER_SIZE
- : (int) filesize);
- if (length < 0) {
- throw new EOFException("Unexpected end of stream.");
- }
- fos.write(buf, 0, length);
- filesize -= length;
- totalLength += length;
- if (filesize == 0) {
- break;
- }
-
- if (trackProgress) {
- percentTransmitted = trackProgress(initFilesize,
- totalLength,
- percentTransmitted);
- }
- }
- } finally {
- final long endTime = System.currentTimeMillis();
- logStats(startTime, endTime, totalLength);
- fos.flush();
- fos.close();
- }
-
- if (getPreserveLastModified()) {
- setLastModified(localFile);
- }
- }
-
- private void setLastModified(final File localFile) throws JSchException {
- SftpATTRS fileAttributes = null;
- final ChannelSftp channel = openSftpChannel();
- channel.connect();
- try {
- fileAttributes = channel.lstat(remoteDir(remoteFile)
- + localFile.getName());
- } catch (final SftpException e) {
- throw new JSchException("failed to stat remote file", e);
- }
- FileUtils.getFileUtils().setFileLastModified(localFile,
- ((long) fileAttributes
- .getMTime())
- * 1000);
- }
-
- /**
- * returns the directory part of the remote file, if any.
- */
- private static String remoteDir(final String remoteFile) {
- int index = remoteFile.lastIndexOf("/");
- if (index < 0) {
- index = remoteFile.lastIndexOf("\\");
- }
- return index > -1 ? remoteFile.substring(0, index + 1) : "";
- }
-}
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java
deleted file mode 100644
index 04f72d23..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.tools.ant.util.FileUtils;
-
-import com.jcraft.jsch.ChannelSftp;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-import com.jcraft.jsch.SftpATTRS;
-import com.jcraft.jsch.SftpException;
-import com.jcraft.jsch.SftpProgressMonitor;
-
-/**
- * A helper object representing an scp download.
- */
-public class ScpFromMessageBySftp extends ScpFromMessage {
-
- private static final int HUNDRED_KILOBYTES = 102400;
-
- private String remoteFile;
- private final File localFile;
- private boolean isRecursive = false;
- private boolean verbose = false;
-
- /**
- * Constructor for ScpFromMessageBySftp.
- * @param verbose if true log extra information
- * @param session the Scp session to use
- * @param aRemoteFile the remote file name
- * @param aLocalFile the local file
- * @param recursive if true use recursion
- * @since Ant 1.7
- */
- public ScpFromMessageBySftp(final boolean verbose,
- final Session session,
- final String aRemoteFile,
- final File aLocalFile,
- final boolean recursive) {
- this(verbose, session, aRemoteFile, aLocalFile, recursive, false);
- }
-
- /**
- * Constructor for ScpFromMessageBySftp.
- * @param session the Scp session to use
- * @param aRemoteFile the remote file name
- * @param aLocalFile the local file
- * @param recursive if true use recursion
- */
- public ScpFromMessageBySftp(final Session session,
- final String aRemoteFile,
- final File aLocalFile,
- final boolean recursive) {
- this(false, session, aRemoteFile, aLocalFile, recursive);
- }
-
- /**
- * Constructor for ScpFromMessageBySftp.
- * @param verbose if true log extra information
- * @param session the Scp session to use
- * @param aRemoteFile the remote file name
- * @param aLocalFile the local file
- * @param recursive if true use recursion
- * @param preserveLastModified whether to preserve file
- * modification times
- * @since Ant 1.8.0
- */
- public ScpFromMessageBySftp(final boolean verbose,
- final Session session,
- final String aRemoteFile,
- final File aLocalFile,
- final boolean recursive,
- final boolean preserveLastModified) {
- super(verbose, session, aRemoteFile, aLocalFile, recursive,
- preserveLastModified);
- this.verbose = verbose;
- this.remoteFile = aRemoteFile;
- this.localFile = aLocalFile;
- this.isRecursive = recursive;
- }
-
- /**
- * Carry out the transfer.
- * @throws IOException on i/o errors
- * @throws JSchException on errors detected by scp
- */
- public void execute() throws IOException, JSchException {
- final ChannelSftp channel = openSftpChannel();
- try {
- channel.connect();
- try {
- final SftpATTRS attrs = channel.stat(remoteFile);
- if (attrs.isDir() && !remoteFile.endsWith("/")) {
- remoteFile = remoteFile + "/";
- }
- } catch (final SftpException ee) {
- // Ignored
- }
- getDir(channel, remoteFile, localFile);
- } catch (final SftpException e) {
- final JSchException schException = new JSchException("Could not get '"+ remoteFile
- +"' to '"+localFile+"' - "
- +e.toString());
- schException.initCause(e);
- throw schException;
- } finally {
- if (channel != null) {
- channel.disconnect();
- }
- }
- log("done\n");
- }
-
- private void getDir(final ChannelSftp channel,
- final String remoteFile,
- final File localFile) throws IOException, SftpException {
- String pwd = remoteFile;
- if (remoteFile.lastIndexOf('/') != -1) {
- if (remoteFile.length() > 1) {
- pwd = remoteFile.substring(0, remoteFile.lastIndexOf('/'));
- }
- }
- channel.cd(pwd);
- if (!localFile.exists()) {
- localFile.mkdirs();
- }
- final java.util.Vector files = channel.ls(remoteFile);
- final int size = files.size();
- for (int i = 0; i < size; i++) {
- final ChannelSftp.LsEntry le = (ChannelSftp.LsEntry) files.elementAt(i);
- final String name = le.getFilename();
- if (le.getAttrs().isDir()) {
- if (name.equals(".") || name.equals("..")) {
- continue;
- }
- getDir(channel,
- channel.pwd() + "/" + name + "/",
- new File(localFile, le.getFilename()));
- } else {
- getFile(channel, le, localFile);
- }
- }
- channel.cd("..");
- }
-
- private void getFile(final ChannelSftp channel,
- final ChannelSftp.LsEntry le,
- File localFile) throws IOException, SftpException {
- final String remoteFile = le.getFilename();
- if (!localFile.exists()) {
- final String path = localFile.getAbsolutePath();
- final int i = path.lastIndexOf(File.pathSeparator);
- if (i != -1) {
- if (path.length() > File.pathSeparator.length()) {
- new File(path.substring(0, i)).mkdirs();
- }
- }
- }
-
- if (localFile.isDirectory()) {
- localFile = new File(localFile, remoteFile);
- }
-
- final long startTime = System.currentTimeMillis();
- final long totalLength = le.getAttrs().getSize();
-
- SftpProgressMonitor monitor = null;
- final boolean trackProgress = getVerbose() && totalLength > HUNDRED_KILOBYTES;
- if (trackProgress) {
- monitor = getProgressMonitor();
- }
- try {
- log("Receiving: " + remoteFile + " : " + le.getAttrs().getSize());
- channel.get(remoteFile, localFile.getAbsolutePath(), monitor);
- } finally {
- final long endTime = System.currentTimeMillis();
- logStats(startTime, endTime, (int) totalLength);
- }
- if (getPreserveLastModified()) {
- FileUtils.getFileUtils().setFileLastModified(localFile,
- ((long) le.getAttrs()
- .getMTime())
- * 1000);
- }
- }
-}
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java
deleted file mode 100644
index 5ba6b559..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Iterator;
-import java.util.List;
-
-import com.jcraft.jsch.Channel;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-
-/**
- * Utility class to carry out an upload scp transfer.
- */
-public class ScpToMessage extends AbstractSshMessage {
-
- private static final int HUNDRED_KILOBYTES = 102400;
- private static final int BUFFER_SIZE = 100*1024;
- private static final int DEFAULT_DIR_MODE = 0755;
- private static final int DEFAULT_FILE_MODE = 0644;
-
- private File localFile;
- private String remotePath;
- private List directoryList;
- private Integer fileMode, dirMode;
-
- /**
- * Constructor for ScpToMessage
- * @param session the ssh session to use
- */
- public ScpToMessage(final Session session) {
- super(session);
- }
-
- /**
- * Constructor for ScpToMessage
- * @param verbose if true do verbose logging
- * @param session the ssh session to use
- * @since Ant 1.7
- */
- public ScpToMessage(final boolean verbose, final Session session) {
- super(verbose, session);
- }
-
- /**
- * Constructor for a local file to remote.
- * @param verbose if true do verbose logging
- * @param session the scp session to use
- * @param aLocalFile the local file
- * @param aRemotePath the remote path
- * @since Ant 1.6.2
- */
- public ScpToMessage(final boolean verbose,
- final Session session,
- final File aLocalFile,
- final String aRemotePath) {
- this(verbose, session, aRemotePath);
-
- this.localFile = aLocalFile;
- }
-
- /**
- * Constructor for a local directories to remote.
- * @param verbose if true do verbose logging
- * @param session the scp session to use
- * @param aDirectoryList a list of directories
- * @param aRemotePath the remote path
- * @since Ant 1.6.2
- */
- public ScpToMessage(final boolean verbose,
- final Session session,
- final List aDirectoryList,
- final String aRemotePath) {
- this(verbose, session, aRemotePath);
-
- this.directoryList = aDirectoryList;
- }
-
- /**
- * Constructor for ScpToMessage.
- * @param verbose if true do verbose logging
- * @param session the scp session to use
- * @param aRemotePath the remote path
- * @since Ant 1.6.2
- */
- private ScpToMessage(final boolean verbose,
- final Session session,
- final String aRemotePath) {
- super(verbose, session);
- this.remotePath = aRemotePath;
- }
-
- /**
- * Constructor for ScpToMessage.
- * @param session the scp session to use
- * @param aLocalFile the local file
- * @param aRemotePath the remote path
- */
- public ScpToMessage(final Session session,
- final File aLocalFile,
- final String aRemotePath) {
- this(false, session, aLocalFile, aRemotePath);
- }
-
- /**
- * Constructor for ScpToMessage.
- * @param session the scp session to use
- * @param aDirectoryList a list of directories
- * @param aRemotePath the remote path
- */
- public ScpToMessage(final Session session,
- final List aDirectoryList,
- final String aRemotePath) {
- this(false, session, aDirectoryList, aRemotePath);
- }
-
- /**
- * Carry out the transfer.
- * @throws IOException on i/o errors
- * @throws JSchException on errors detected by scp
- */
- @Override
- public void execute() throws IOException, JSchException {
- if (directoryList != null) {
- doMultipleTransfer();
- }
- if (localFile != null) {
- doSingleTransfer();
- }
- log("done.\n");
- }
-
- private void doSingleTransfer() throws IOException, JSchException {
- final String cmd = "scp -t " + remotePath;
- final Channel channel = openExecChannel(cmd);
- try {
-
- final OutputStream out = channel.getOutputStream();
- final InputStream in = channel.getInputStream();
-
- channel.connect();
-
- waitForAck(in);
- sendFileToRemote(localFile, in, out);
- } finally {
- if (channel != null) {
- channel.disconnect();
- }
- }
- }
-
- private void doMultipleTransfer() throws IOException, JSchException {
- final Channel channel = openExecChannel("scp -r -d -t " + remotePath);
- try {
- final OutputStream out = channel.getOutputStream();
- final InputStream in = channel.getInputStream();
-
- channel.connect();
-
- waitForAck(in);
- for (final Iterator i = directoryList.iterator(); i.hasNext();) {
- final Directory current = (Directory) i.next();
- sendDirectory(current, in, out);
- }
- } finally {
- if (channel != null) {
- channel.disconnect();
- }
- }
- }
-
- private void sendDirectory(final Directory current,
- final InputStream in,
- final OutputStream out) throws IOException {
- for (final Iterator fileIt = current.filesIterator(); fileIt.hasNext();) {
- sendFileToRemote((File) fileIt.next(), in, out);
- }
- for (final Iterator dirIt = current.directoryIterator(); dirIt.hasNext();) {
- final Directory dir = (Directory) dirIt.next();
- sendDirectoryToRemote(dir, in, out);
- }
- }
-
- private void sendDirectoryToRemote(final Directory directory,
- final InputStream in,
- final OutputStream out) throws IOException {
- String command = "D0";
- command += Integer.toOctalString(getDirMode());
- command += " 0 ";
- command += directory.getDirectory().getName();
- command += "\n";
-
- out.write(command.getBytes());
- out.flush();
-
- waitForAck(in);
- sendDirectory(directory, in, out);
- out.write("E\n".getBytes());
- out.flush();
- waitForAck(in);
- }
-
- private void sendFileToRemote(final File localFile,
- final InputStream in,
- final OutputStream out) throws IOException {
- // send "C0644 filesize filename", where filename should not include '/'
- final long filesize = localFile.length();
- String command = "C0";
- command += Integer.toOctalString(getFileMode());
- command += " " + filesize + " ";
- command += localFile.getName();
- command += "\n";
-
- out.write(command.getBytes());
- out.flush();
-
- waitForAck(in);
-
- // send a content of lfile
- final FileInputStream fis = new FileInputStream(localFile);
- final byte[] buf = new byte[BUFFER_SIZE];
- final long startTime = System.currentTimeMillis();
- long totalLength = 0;
-
- // only track progress for files larger than 100kb in verbose mode
- final boolean trackProgress = getVerbose() && filesize > HUNDRED_KILOBYTES;
- // since filesize keeps on decreasing we have to store the
- // initial filesize
- final long initFilesize = filesize;
- int percentTransmitted = 0;
-
- try {
- if (this.getVerbose()) {
- log("Sending: " + localFile.getName() + " : " + localFile.length());
- }
- while (true) {
- final int len = fis.read(buf, 0, buf.length);
- if (len <= 0) {
- break;
- }
- out.write(buf, 0, len);
- totalLength += len;
-
- if (trackProgress) {
- percentTransmitted = trackProgress(initFilesize,
- totalLength,
- percentTransmitted);
- }
- }
- out.flush();
- sendAck(out);
- waitForAck(in);
- } finally {
- if (this.getVerbose()) {
- final long endTime = System.currentTimeMillis();
- logStats(startTime, endTime, totalLength);
- }
- fis.close();
- }
- }
-
- /**
- * Get the local file
- * @return the local file
- */
- public File getLocalFile() {
- return localFile;
- }
-
- /**
- * Get the remote path
- * @return the remote path
- */
- public String getRemotePath() {
- return remotePath;
- }
-
- /**
- * Set the file mode, defaults to 0644.
- * @since Ant 1.9.5
- */
- public void setFileMode(int fileMode) {
- this.fileMode = fileMode;
- }
-
- /**
- * Get the file mode.
- * @since Ant 1.9.5
- */
- public int getFileMode() {
- return fileMode != null ? fileMode.intValue() : DEFAULT_FILE_MODE;
- }
-
- /**
- * Set the dir mode, defaults to 0755.
- * @since Ant 1.9.5
- */
- public void setDirMode(int dirMode) {
- this.dirMode = dirMode;
- }
-
- /**
- * Get the dir mode.
- * @since Ant 1.9.5
- */
- public int getDirMode() {
- return dirMode != null ? dirMode.intValue() : DEFAULT_DIR_MODE;
- }
-
-}
diff --git a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java b/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java
deleted file mode 100644
index 2b32907d..00000000
--- a/framework/src/ant/apache-ant-1.9.6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-
-import com.jcraft.jsch.ChannelSftp;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-import com.jcraft.jsch.SftpException;
-import com.jcraft.jsch.SftpProgressMonitor;
-
-/**
- * Utility class to carry out an upload by sftp.
- */
-public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ {
-
- private static final int HUNDRED_KILOBYTES = 102400;
-
- private File localFile;
- private final String remotePath;
- private List directoryList;
-
- /**
- * Constructor for a local file to remote.
- * @param verbose if true do verbose logging
- * @param session the scp session to use
- * @param aLocalFile the local file
- * @param aRemotePath the remote path
- * @since Ant 1.7
- */
- public ScpToMessageBySftp(final boolean verbose,
- final Session session,
- final File aLocalFile,
- final String aRemotePath) {
- this(verbose, session, aRemotePath);
-
- this.localFile = aLocalFile;
- }
-
- /**
- * Constructor for a local directories to remote.
- * @param verbose if true do verbose logging
- * @param session the scp session to use
- * @param aDirectoryList a list of directories
- * @param aRemotePath the remote path
- * @since Ant 1.7
- */
- public ScpToMessageBySftp(final boolean verbose,
- final Session session,
- final List aDirectoryList,
- final String aRemotePath) {
- this(verbose, session, aRemotePath);
-
- this.directoryList = aDirectoryList;
- }
-
- /**
- * Constructor for ScpToMessage.
- * @param verbose if true do verbose logging
- * @param session the scp session to use
- * @param aRemotePath the remote path
- * @since Ant 1.6.2
- */
- private ScpToMessageBySftp(final boolean verbose,
- final Session session,
- final String aRemotePath) {
- super(verbose, session);
- this.remotePath = aRemotePath;
- }
-
- /**
- * Constructor for ScpToMessage.
- * @param session the scp session to use
- * @param aLocalFile the local file
- * @param aRemotePath the remote path
- */
- public ScpToMessageBySftp(final Session session,
- final File aLocalFile,
- final String aRemotePath) {
- this(false, session, aLocalFile, aRemotePath);
- }
-
- /**
- * Constructor for ScpToMessage.
- * @param session the scp session to use
- * @param aDirectoryList a list of directories
- * @param aRemotePath the remote path
- */
- public ScpToMessageBySftp(final Session session,
- final List aDirectoryList,
- final String aRemotePath) {
- this(false, session, aDirectoryList, aRemotePath);
- }
-
- /**
- * Carry out the transfer.
- * @throws IOException on i/o errors
- * @throws JSchException on errors detected by scp
- */
- @Override
- public void execute() throws IOException, JSchException {
- if (directoryList != null) {
- doMultipleTransfer();
- }
- if (localFile != null) {
- doSingleTransfer();
- }
- log("done.\n");
- }
-
- private void doSingleTransfer() throws IOException, JSchException {
- final ChannelSftp channel = openSftpChannel();
- try {
- channel.connect();
- try {
- sendFileToRemote(channel, localFile, remotePath);
- } catch (final SftpException e) {
- final JSchException schException = new JSchException("Could not send '" + localFile
- + "' to '" + remotePath + "' - "
- + e.toString());
- schException.initCause(e);
- throw schException;
- }
- } finally {
- if (channel != null) {
- channel.disconnect();
- }
- }
- }
-
- private void doMultipleTransfer() throws IOException, JSchException {
- final ChannelSftp channel = openSftpChannel();
- try {
- channel.connect();
-
- try {
- try {
- channel.stat(remotePath);
- } catch (final SftpException e) {
- if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
- // dir does not exist.
- channel.mkdir(remotePath);
- channel.chmod(getDirMode(), remotePath);
- } else {
- throw new JSchException("failed to access remote dir '"
- + remotePath + "'", e);
- }
- }
- channel.cd(remotePath);
- } catch (final SftpException e) {
- throw new JSchException("Could not CD to '" + remotePath
- + "' - " + e.toString(), e);
- }
- Directory current = null;
- try {
- for (final Iterator i = directoryList.iterator(); i.hasNext();) {
- current = (Directory) i.next();
- if (getVerbose()) {
- log("Sending directory " + current);
- }
- sendDirectory(channel, current);
- }
- } catch (final SftpException e) {
- String msg = "Error sending directory";
- if (current != null && current.getDirectory() != null) {
- msg += " '" + current.getDirectory().getName() + "'";
- }
- throw new JSchException(msg, e);
- }
- } finally {
- if (channel != null) {
- channel.disconnect();
- }
- }
- }
-
- private void sendDirectory(final ChannelSftp channel,
- final Directory current)
- throws IOException, SftpException {
- for (final Iterator fileIt = current.filesIterator(); fileIt.hasNext();) {
- sendFileToRemote(channel, (File) fileIt.next(), null);
- }
- for (final Iterator dirIt = current.directoryIterator(); dirIt.hasNext();) {
- final Directory dir = (Directory) dirIt.next();
- sendDirectoryToRemote(channel, dir);
- }
- }
-
- private void sendDirectoryToRemote(final ChannelSftp channel,
- final Directory directory)
- throws IOException, SftpException {
- final String dir = directory.getDirectory().getName();
- try {
- channel.stat(dir);
- } catch (final SftpException e) {
- // dir does not exist.
- if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
- channel.mkdir(dir);
- channel.chmod(getDirMode(), dir);
- }
- }
- channel.cd(dir);
- sendDirectory(channel, directory);
- channel.cd("..");
- }
-
- private void sendFileToRemote(final ChannelSftp channel,
- final File localFile,
- String remotePath)
- throws IOException, SftpException {
- final long filesize = localFile.length();
-
- if (remotePath == null) {
- remotePath = localFile.getName();
- }
-
- final long startTime = System.currentTimeMillis();
- final long totalLength = filesize;
-
- // only track progress for files larger than 100kb in verbose mode
- final boolean trackProgress = getVerbose() && filesize > HUNDRED_KILOBYTES;
-
- SftpProgressMonitor monitor = null;
- if (trackProgress) {
- monitor = getProgressMonitor();
- }
-
- try {
- if (this.getVerbose()) {
- log("Sending: " + localFile.getName() + " : " + filesize);
- }
- channel.put(localFile.getAbsolutePath(), remotePath, monitor);
- channel.chmod(getFileMode(), remotePath);
- } finally {
- if (this.getVerbose()) {
- final long endTime = System.currentTimeMillis();
- logStats(startTime, endTime, (int) totalLength);
- }
- }
- }
-
- /**
- * Get the local file.
- * @return the local file.
- */
- public File getLocalFile() {
- return localFile;
- }
-
- /**
- * Get the remote path.
- * @return the remote path.
- */
- public String getRemotePath() {
- return remotePath;
- }
-}