/** Upload a local file from {@code localFile} to {@code targetPath} on the remote host. */ public synchronized int copy(LocalSourceFile sourceFile, String remotePath) throws IOException { return copy(sourceFile, remotePath, ScpCommandLine.EscapeMode.SingleQuote); }
public SCPUploadClient newSCPUploadClient() { return new SCPUploadClient(newSCPEngine(), bandwidthLimit); }
private void sendDirectory(TransferListener listener, LocalSourceFile f) throws IOException { preserveTimeIfPossible(f); engine.sendMessage("D0" + getPermString(f) + " 0 " + f.getName()); for (LocalSourceFile child : f.getChildren(uploadFilter)) process(listener, child); engine.sendMessage("E"); }
private void process(TransferListener listener, LocalSourceFile f) throws IOException { if (f.isDirectory()) { sendDirectory(listener.directory(f.getName()), f); } else if (f.isFile()) { sendFile(listener.file(f.getName(), f.getLength()), f); } else throw new IOException(f + " is not a regular file or directory"); }
private void sendFile(StreamCopier.Listener listener, LocalSourceFile f) throws IOException { preserveTimeIfPossible(f); final InputStream src = f.getInputStream(); try { engine.sendMessage("C0" + getPermString(f) + " " + f.getLength() + " " + f.getName()); engine.transferToRemote(listener, src, f.getLength()); engine.signal("Transfer done"); engine.check("Remote agrees transfer done"); } finally { IOUtils.closeQuietly(src); } }
SSHClient client = null; SCPUploadClient uploader = null; try { client = getClient(); uploader = client.newSCPFileTransfer().newSCPUploadClient(); uploader.setUploadFilter(new WildcardFileFilter(wildCardPattern)); //determine the remote directory File f = new File(localDirLocation); String dir = remoteDirLocation + f.getName(); uploader.copy(new FileSystemFile(localDirLocation), remoteDirLocation); } catch (IOException e) { //processing exceptions here } finally { disconnectClient(client); }
public synchronized int copy(LocalSourceFile sourceFile, String remotePath, ScpCommandLine.EscapeMode escapeMode) throws IOException { engine.cleanSlate(); try { startCopy(sourceFile, remotePath, escapeMode); } finally { engine.exit(); } return engine.getExitStatus(); }
private void startCopy(LocalSourceFile sourceFile, String targetPath, ScpCommandLine.EscapeMode escapeMode) throws IOException { ScpCommandLine commandLine = ScpCommandLine.with(ScpCommandLine.Arg.SINK) .and(ScpCommandLine.Arg.RECURSIVE) .and(ScpCommandLine.Arg.PRESERVE_TIMES, sourceFile.providesAtimeMtime()) .and(ScpCommandLine.Arg.LIMIT, String.valueOf(bandwidthLimit), (bandwidthLimit > 0)); commandLine.withPath(targetPath, escapeMode); engine.execSCPWith(commandLine); engine.check("Start status OK"); process(engine.getTransferListener(), sourceFile); }
private void process(TransferListener listener, LocalSourceFile f) throws IOException { if (f.isDirectory()) { sendDirectory(listener.directory(f.getName()), f); } else if (f.isFile()) { sendFile(listener.file(f.getName(), f.getLength()), f); } else throw new IOException(f + " is not a regular file or directory"); }
private void sendFile(StreamCopier.Listener listener, LocalSourceFile f) throws IOException { preserveTimeIfPossible(f); final InputStream src = f.getInputStream(); try { engine.sendMessage("C0" + getPermString(f) + " " + f.getLength() + " " + f.getName()); engine.transferToRemote(listener, src, f.getLength()); engine.signal("Transfer done"); engine.check("Remote agrees transfer done"); } finally { IOUtils.closeQuietly(src); } }
/** Upload a local file from {@code localFile} to {@code targetPath} on the remote host. */ public synchronized int copy(LocalSourceFile sourceFile, String remotePath) throws IOException { engine.cleanSlate(); try { startCopy(sourceFile, remotePath); } finally { engine.exit(); } return engine.getExitStatus(); }
private synchronized void startCopy(LocalSourceFile sourceFile, String targetPath) throws IOException { List<Arg> args = new LinkedList<Arg>(); args.add(Arg.SINK); args.add(Arg.RECURSIVE); if (sourceFile.providesAtimeMtime()) args.add(Arg.PRESERVE_TIMES); engine.execSCPWith(args, targetPath); engine.check("Start status OK"); process(engine.getTransferListener(), sourceFile); }
private void sendDirectory(TransferListener listener, LocalSourceFile f) throws IOException { preserveTimeIfPossible(f); engine.sendMessage("D0" + getPermString(f) + " 0 " + f.getName()); for (LocalSourceFile child : f.getChildren(uploadFilter)) process(listener, child); engine.sendMessage("E"); }
@Override public void upload(LocalSourceFile localFile, String remotePath) throws IOException { newSCPUploadClient().copy(localFile, remotePath); }
private void process(TransferListener listener, LocalSourceFile f) throws IOException { if (f.isDirectory()) { sendDirectory(listener.directory(f.getName()), f); } else if (f.isFile()) { sendFile(listener.file(f.getName(), f.getLength()), f); } else throw new IOException(f + " is not a regular file or directory"); }
private void sendFile(StreamCopier.Listener listener, LocalSourceFile f) throws IOException { preserveTimeIfPossible(f); final InputStream src = f.getInputStream(); try { engine.sendMessage("C0" + getPermString(f) + " " + f.getLength() + " " + f.getName()); engine.transferToRemote(listener, src, f.getLength()); engine.signal("Transfer done"); engine.check("Remote agrees transfer done"); } finally { IOUtils.closeQuietly(src); } }
public synchronized int copy(LocalSourceFile sourceFile, String remotePath, ScpCommandLine.EscapeMode escapeMode) throws IOException { engine.cleanSlate(); try { startCopy(sourceFile, remotePath, escapeMode); } finally { engine.exit(); } return engine.getExitStatus(); }
private void startCopy(LocalSourceFile sourceFile, String targetPath, ScpCommandLine.EscapeMode escapeMode) throws IOException { ScpCommandLine commandLine = ScpCommandLine.with(ScpCommandLine.Arg.SINK) .and(ScpCommandLine.Arg.RECURSIVE) .and(ScpCommandLine.Arg.PRESERVE_TIMES, sourceFile.providesAtimeMtime()) .and(ScpCommandLine.Arg.LIMIT, String.valueOf(bandwidthLimit), (bandwidthLimit > 0)); commandLine.withPath(targetPath, escapeMode); engine.execSCPWith(commandLine); engine.check("Start status OK"); process(engine.getTransferListener(), sourceFile); }
public SCPUploadClient newSCPUploadClient() { return new SCPUploadClient(newSCPEngine()); }
private void sendDirectory(TransferListener listener, LocalSourceFile f) throws IOException { preserveTimeIfPossible(f); engine.sendMessage("D0" + getPermString(f) + " 0 " + f.getName()); for (LocalSourceFile child : f.getChildren(uploadFilter)) process(listener, child); engine.sendMessage("E"); }