in wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/ScpCommand.java [152:256]
public void run() {
int exitValue = OK;
String exitMessage = null;
try {
if (optT) {
ack();
for (; ; ) {
String line;
boolean isDir = false;
int c = readAck(true);
switch (c) {
case -1:
return;
case 'D':
isDir = true;
case 'C':
line = ((char) c) + readLine();
break;
case 'E':
readLine();
return;
default:
// a real ack that has been acted upon already
continue;
}
if (optR && isDir) {
writeDir(line, root.getFile(path));
} else {
writeFile(line, root.getFile(path));
}
}
} else if (optF) {
String pattern = path;
int idx = pattern.indexOf('*');
if (idx >= 0) {
String basedir = "";
int lastSep = pattern.substring(0, idx).lastIndexOf('/');
if (lastSep >= 0) {
basedir = pattern.substring(0, lastSep);
pattern = pattern.substring(lastSep + 1);
}
String[] included = new DirectoryScanner(basedir, pattern).scan();
for (String path : included) {
SshFile file = root.getFile(basedir + "/" + path);
if (file.isFile()) {
readFile(file);
} else if (file.isDirectory()) {
if (!optR) {
out.write(WARNING);
out.write((path + " not a regular file\n").getBytes());
} else {
readDir(file);
}
} else {
out.write(WARNING);
out.write((path + " unknown file type\n").getBytes());
}
}
} else {
String basedir = "";
int lastSep = pattern.lastIndexOf('/');
if (lastSep >= 0) {
basedir = pattern.substring(0, lastSep);
pattern = pattern.substring(lastSep + 1);
}
SshFile file = root.getFile(basedir + "/" + pattern);
if (!file.doesExist()) {
exitValue = WARNING;
throw new IOException(file + ": no such file or directory");
}
if (file.isFile()) {
readFile(file);
} else if (file.isDirectory()) {
if (!optR) {
throw new IOException(file + " not a regular file");
} else {
readDir(file);
}
} else {
throw new IOException(file + ": unknown file type");
}
}
} else {
throw new IOException("Unsupported mode");
}
} catch (IOException e) {
try {
exitValue = (exitValue != OK ? exitValue : ERROR);
exitMessage = e.getMessage();
out.write(exitValue);
out.write(exitMessage.getBytes());
out.write('\n');
out.flush();
} catch (IOException e2) {
// Ignore
}
LOG.info("Error in scp command", e);
} finally {
if (callback != null) {
callback.onExit(exitValue, exitMessage);
}
}
}