Methods Summary |
---|
public abstract void | execute()Carry out the transfer.
|
protected com.jcraft.jsch.SftpProgressMonitor | getProgressMonitor()Get the progress monitor.
if (monitor == null) {
monitor = new ProgressMonitor();
}
return monitor;
|
protected final boolean | getVerbose()Is the verbose attribute set.
return verbose;
|
protected void | log(java.lang.String message)Log a message to the log listener.
listener.log(message);
|
protected void | logStats(long timeStarted, long timeEnded, long totalLength)Log transfer stats to the log listener.
double duration = (timeEnded - timeStarted) / 1000.0;
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");
|
protected com.jcraft.jsch.Channel | openExecChannel(java.lang.String command)Open an ssh channel.
ChannelExec channel = (ChannelExec) session.openChannel("exec");
channel.setCommand(command);
return channel;
|
protected com.jcraft.jsch.ChannelSftp | openSftpChannel()Open an ssh sftp channel.
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
return channel;
|
protected void | sendAck(java.io.OutputStream out)Send an ack.
byte[] buf = new byte[1];
buf[0] = 0;
out.write(buf);
out.flush();
|
public void | setLogListener(LogListener aListener)Set a log listener.
listener = aListener;
|
protected final int | trackProgress(long filesize, long totalLength, int percentTransmitted)Track progress every 10% if 100kb < filesize < 1mb. For larger
files track progress for every percent transmitted.
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(".");
}
}
}
return percent;
|
protected void | waitForAck(java.io.InputStream in)Reads the response, throws a BuildException if the response
indicates an error.
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) {
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());
}
}
|