git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@477342 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -23,8 +23,6 @@ import com.jcraft.jsch.ChannelExec; | |||
| import com.jcraft.jsch.JSchException; | |||
| import com.jcraft.jsch.Session; | |||
| import com.jcraft.jsch.ChannelSftp; | |||
| import com.jcraft.jsch.SftpATTRS; | |||
| import com.jcraft.jsch.SftpException; | |||
| import com.jcraft.jsch.SftpProgressMonitor; | |||
| import java.io.IOException; | |||
| @@ -231,7 +229,11 @@ public abstract class AbstractSshMessage { | |||
| private ProgressMonitor monitor = null; | |||
| protected SftpProgressMonitor getProgressMonitor(){ | |||
| /** | |||
| * Get the progress monitor. | |||
| * @return the progress monitor. | |||
| */ | |||
| protected SftpProgressMonitor getProgressMonitor() { | |||
| if (monitor == null) { | |||
| monitor = new ProgressMonitor(); | |||
| } | |||
| @@ -190,6 +190,16 @@ public class SSHUserInfo implements UserInfo, UIKeyboardInteractive { | |||
| //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, | |||
| @@ -20,15 +20,9 @@ package org.apache.tools.ant.taskdefs.optional.ssh; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.EOFException; | |||
| import java.io.InputStream; | |||
| import java.io.OutputStream; | |||
| import java.io.FileOutputStream; | |||
| import java.io.ByteArrayOutputStream; | |||
| import com.jcraft.jsch.JSchException; | |||
| import com.jcraft.jsch.Session; | |||
| import com.jcraft.jsch.Channel; | |||
| import com.jcraft.jsch.ChannelSftp; | |||
| import com.jcraft.jsch.SftpException; | |||
| import com.jcraft.jsch.SftpATTRS; | |||
| @@ -91,12 +85,13 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
| try { | |||
| SftpATTRS attrs = channel.stat(remoteFile); | |||
| if (attrs.isDir() && !remoteFile.endsWith("/")) { | |||
| remoteFile=remoteFile+"/"; | |||
| remoteFile = remoteFile + "/"; | |||
| } | |||
| } catch(SftpException ee) { | |||
| } catch (SftpException ee) { | |||
| // Ignored | |||
| } | |||
| getDir(channel, remoteFile, localFile); | |||
| } catch(SftpException e) { | |||
| } catch (SftpException e) { | |||
| throw new JSchException(e.toString()); | |||
| } finally { | |||
| if (channel != null) { | |||
| @@ -109,10 +104,10 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
| private void getDir(ChannelSftp channel, | |||
| String remoteFile, | |||
| File localFile) throws IOException, SftpException { | |||
| String pwd=remoteFile; | |||
| if (remoteFile.lastIndexOf('/')!=-1) { | |||
| if (remoteFile.length()>1) { | |||
| pwd=remoteFile.substring(0, remoteFile.lastIndexOf('/')); | |||
| String pwd = remoteFile; | |||
| if (remoteFile.lastIndexOf('/') != -1) { | |||
| if (remoteFile.length() > 1) { | |||
| pwd = remoteFile.substring(0, remoteFile.lastIndexOf('/')); | |||
| } | |||
| } | |||
| channel.cd(pwd); | |||
| @@ -120,7 +115,7 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
| localFile.mkdirs(); | |||
| } | |||
| java.util.Vector files = channel.ls(remoteFile); | |||
| for(int i = 0; i < files.size(); i++){ | |||
| for (int i = 0; i < files.size(); i++) { | |||
| ChannelSftp.LsEntry le = (ChannelSftp.LsEntry) files.elementAt(i); | |||
| String name = le.getFilename(); | |||
| if (le.getAttrs().isDir()) { | |||
| @@ -130,7 +125,7 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
| getDir(channel, | |||
| channel.pwd() + "/" + name + "/", | |||
| new File(localFile, le.getFilename())); | |||
| } else{ | |||
| } else { | |||
| getFile(channel, le, localFile); | |||
| } | |||
| } | |||
| @@ -145,14 +140,14 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
| String path = localFile.getAbsolutePath(); | |||
| int i = 0; | |||
| if ((i = path.lastIndexOf(File.pathSeparator)) != -1) { | |||
| if (path.length()>File.pathSeparator.length()) { | |||
| if (path.length() > File.pathSeparator.length()) { | |||
| new File(path.substring(0, i)).mkdirs(); | |||
| } | |||
| } | |||
| } | |||
| if (localFile.isDirectory()) { | |||
| localFile=new File(localFile, remoteFile); | |||
| localFile = new File(localFile, remoteFile); | |||
| } | |||
| long startTime = System.currentTimeMillis(); | |||
| @@ -160,15 +155,15 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
| SftpProgressMonitor monitor = null; | |||
| boolean trackProgress = getVerbose() && totalLength > 102400; | |||
| if (trackProgress){ | |||
| if (trackProgress) { | |||
| monitor = getProgressMonitor(); | |||
| } | |||
| try{ | |||
| try { | |||
| log("Receiving: " + remoteFile + " : " + le.getAttrs().getSize()); | |||
| channel.get(remoteFile, localFile.getAbsolutePath(), monitor); | |||
| } finally{ | |||
| } finally { | |||
| long endTime = System.currentTimeMillis(); | |||
| logStats(startTime, endTime, (int)totalLength); | |||
| logStats(startTime, endTime, (int) totalLength); | |||
| } | |||
| } | |||
| } | |||
| @@ -18,19 +18,14 @@ | |||
| package org.apache.tools.ant.taskdefs.optional.ssh; | |||
| import com.jcraft.jsch.Channel; | |||
| import com.jcraft.jsch.Session; | |||
| import com.jcraft.jsch.ChannelSftp; | |||
| import com.jcraft.jsch.JSchException; | |||
| import com.jcraft.jsch.SftpException; | |||
| import com.jcraft.jsch.SftpProgressMonitor; | |||
| import com.jcraft.jsch.SftpATTRS; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.io.FileInputStream; | |||
| import java.io.OutputStream; | |||
| import java.util.List; | |||
| import java.util.Iterator; | |||
| @@ -134,10 +129,9 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
| ChannelSftp channel = openSftpChannel(); | |||
| try { | |||
| channel.connect(); | |||
| try{ | |||
| try { | |||
| sendFileToRemote(channel, localFile, remotePath); | |||
| } | |||
| catch(SftpException e){ | |||
| } catch (SftpException e) { | |||
| throw new JSchException(e.toString()); | |||
| } | |||
| } finally { | |||
| @@ -152,14 +146,13 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
| try { | |||
| channel.connect(); | |||
| try{ | |||
| try { | |||
| channel.cd(remotePath); | |||
| for (Iterator i = directoryList.iterator(); i.hasNext();) { | |||
| Directory current = (Directory) i.next(); | |||
| sendDirectory(channel, current); | |||
| } | |||
| } | |||
| catch(SftpException e){ | |||
| } catch (SftpException e) { | |||
| throw new JSchException(e.toString()); | |||
| } | |||
| } finally { | |||
| @@ -184,13 +177,12 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
| private void sendDirectoryToRemote(ChannelSftp channel, | |||
| Directory directory) | |||
| throws IOException, SftpException { | |||
| String dir=directory.getDirectory().getName(); | |||
| try{ | |||
| String dir = directory.getDirectory().getName(); | |||
| try { | |||
| channel.stat(dir); | |||
| } | |||
| catch (SftpException e) { | |||
| } catch (SftpException e) { | |||
| // dir does not exist. | |||
| if (e.id==ChannelSftp.SSH_FX_NO_SUCH_FILE) { | |||
| if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { | |||
| channel.mkdir(dir); | |||
| } | |||
| } | |||
| @@ -205,8 +197,8 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
| throws IOException, SftpException { | |||
| long filesize = localFile.length(); | |||
| if (remotePath==null) { | |||
| remotePath=localFile.getName(); | |||
| if (remotePath == null) { | |||
| remotePath = localFile.getName(); | |||
| } | |||
| long startTime = System.currentTimeMillis(); | |||
| @@ -216,17 +208,16 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
| boolean trackProgress = getVerbose() && filesize > 102400; | |||
| SftpProgressMonitor monitor = null; | |||
| if (trackProgress){ | |||
| if (trackProgress) { | |||
| monitor = getProgressMonitor(); | |||
| } | |||
| try{ | |||
| try { | |||
| if (this.getVerbose()) { | |||
| log("Sending: " + localFile.getName() + " : " + filesize); | |||
| } | |||
| channel.put(localFile.getAbsolutePath(), remotePath, monitor); | |||
| } | |||
| finally { | |||
| } finally { | |||
| if (this.getVerbose()) { | |||
| long endTime = System.currentTimeMillis(); | |||
| logStats(startTime, endTime, (int) totalLength); | |||
| @@ -234,10 +225,18 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
| } | |||
| } | |||
| /** | |||
| * 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; | |||
| } | |||