Implements a Secure Copy (SCP) client. This may be useful when the server
does not support SFTP.
| Method from com.sshtools.j2ssh.ScpClient Detail: |
public InputStream get(String remoteFile) throws IOException {
ScpChannel scp = new ScpChannel("scp " + "-f " + (verbose ? "-v " : "")
+ remoteFile);
scp.addEventListener(eventListener);
if (!ssh.openChannel(scp)) {
throw new IOException("Failed to open SCP Channel");
}
return scp.readStreamFromRemote();
}
|
public void get(String localFile,
String[] remoteFiles,
boolean recursive) throws IOException {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < remoteFiles.length; i++) {
buf.append("\"");
buf.append(remoteFiles[i]);
buf.append("\" ");
}
String remoteFile = buf.toString();
remoteFile = remoteFile.trim();
get(localFile, remoteFile, recursive);
}
|
public void get(String localFile,
String remoteFile,
boolean recursive) throws IOException {
if ( (localFile == null) || localFile.equals("")) {
localFile = ".";
}
File lf = new File(localFile);
if (!lf.isAbsolute()) {
lf = new File(cwd, localFile);
}
if (lf.exists() && !lf.isFile() && !lf.isDirectory()) {
throw new IOException(localFile
+ " is not a regular file or directory");
}
ScpChannel scp = new ScpChannel("scp " + "-f "
+ (recursive ? "-r " : "") +
(verbose ? "-v " : "")
+ remoteFile);
scp.addEventListener(eventListener);
if (!ssh.openChannel(scp)) {
throw new IOException("Failed to open SCP Channel");
}
scp.readFromRemote(lf);
scp.close();
}
|
public void put(String localFile,
String remoteFile,
boolean recursive) throws IOException {
File lf = new File(localFile);
if (!lf.isAbsolute()) {
lf = new File(cwd, localFile);
}
if (!lf.exists()) {
throw new IOException(localFile + " does not exist");
}
if (!lf.isFile() && !lf.isDirectory()) {
throw new IOException(localFile
+ " is not a regular file or directory");
}
if (lf.isDirectory() && !recursive) {
throw new IOException(localFile
+ " is a directory, use recursive mode");
}
if ( (remoteFile == null) || remoteFile.equals("")) {
remoteFile = ".";
}
ScpChannel scp = new ScpChannel("scp "
+ (lf.isDirectory() ? "-d " : "") + "-t "
+ (recursive ? "-r " : "") +
(verbose ? "-v " : "")
+ remoteFile);
scp.addEventListener(eventListener);
if (!ssh.openChannel(scp)) {
throw new IOException("Failed to open SCP channel");
}
scp.waitForResponse();
scp.writeFileToRemote(lf, recursive);
scp.close();
}
|
public void put(String[] localFiles,
String remoteFile,
boolean recursive) throws IOException {
if ( (remoteFile == null) || remoteFile.equals("")) {
remoteFile = ".";
}
if (localFiles.length == 1) {
put(localFiles[0], remoteFile, recursive);
}
else {
ScpChannel scp = new ScpChannel("scp " + "-d -t "
+ (recursive ? "-r " : "") +
(verbose ? "-v " : "")
+ remoteFile);
scp.addEventListener(eventListener);
if (!ssh.openChannel(scp)) {
throw new IOException("Failed to open SCP channel");
}
scp.waitForResponse();
for (int i = 0; i < localFiles.length; i++) {
File lf = new File(localFiles[i]);
if (!lf.isAbsolute()) {
lf = new File(cwd, localFiles[i]);
}
if (!lf.isFile() && !lf.isDirectory()) {
throw new IOException(lf.getName()
+ " is not a regular file or directory");
}
scp.writeFileToRemote(lf, recursive);
}
scp.close();
}
}
|
public void put(InputStream in,
long length,
String localFile,
String remoteFile) throws IOException {
ScpChannel scp = new ScpChannel("scp -t " + (verbose ? "-v " : "")
+ remoteFile);
scp.addEventListener(eventListener);
if (!ssh.openChannel(scp)) {
throw new IOException("Failed to open SCP channel");
}
scp.waitForResponse();
scp.writeStreamToRemote(in, length, localFile);
scp.close();
}
Uploads a java.io.InputStream to a remove server as file.
You must supply the correct number of bytes that will
be written.
|