final Pipe p = Pipe.createRemoteToLocal(); actAsync(new SecureFileCallable<Void>() { private static final long serialVersionUID = 1L;
/** * Reads this file. */ public InputStream read() throws IOException, InterruptedException { if(channel==null) { return Files.newInputStream(fileToPath(reading(new File(remote)))); } final Pipe p = Pipe.createRemoteToLocal(); actAsync(new Read(p)); return p.getIn(); } private class Read extends SecureFileCallable<Void> {
@Override public Channel launchChannel(String[] cmd, OutputStream err, FilePath _workDir, Map<String,String> envOverrides) throws IOException, InterruptedException { printCommandLine(cmd, _workDir); Pipe out = Pipe.createRemoteToLocal(); final String workDir = _workDir==null ? null : _workDir.getRemote(); OutputStream os = getChannel().call(new RemoteChannelLaunchCallable(cmd, out, err, workDir, envOverrides)); return new Channel("remotely launched channel on "+channel, Computer.threadPoolForRemoting, out.getIn(), new BufferedOutputStream(os)); }
/** * Authenticate ourselves against the server. * * @return * identity of the server represented as a public key. * @deprecated Specific to {@link Mode#REMOTING}. */ @Deprecated public PublicKey authenticate(Iterable<KeyPair> privateKeys) throws IOException, GeneralSecurityException { Pipe c2s = Pipe.createLocalToRemote(); Pipe s2c = Pipe.createRemoteToLocal(); entryPoint.authenticate("ssh",c2s, s2c); Connection c = new Connection(s2c.getIn(), c2s.getOut()); try { byte[] sharedSecret = c.diffieHellman(false).generateSecret(); PublicKey serverIdentity = c.verifyIdentity(sharedSecret); // try all the public keys for (KeyPair key : privateKeys) { c.proveIdentity(sharedSecret,key); if (c.readBoolean()) return serverIdentity; // succeeded } if (privateKeys.iterator().hasNext()) throw new GeneralSecurityException("Authentication failed. No private key accepted."); else throw new GeneralSecurityException("No private key is available for use in authentication"); } finally { c.close(); } }
final Pipe pipe = Pipe.createRemoteToLocal();
/** * Reads this file. */ public InputStream read() throws IOException { if(channel==null) return new FileInputStream(new File(remote)); final Pipe p = Pipe.createRemoteToLocal(); channel.callAsync(new Callable<Void,IOException>() { public Void call() throws IOException { FileInputStream fis=null; try { fis = new FileInputStream(new File(remote)); Util.copyStream(fis,p.getOut()); return null; } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(p.getOut()); } } }); return p.getIn(); }
/** * Reads this file. */ public InputStream read() throws IOException { if (channel == null) { return new FileInputStream(new File(remote)); } final Pipe p = Pipe.createRemoteToLocal(); channel.callAsync(new Callable<Void, IOException>() { public Void call() throws IOException { FileInputStream fis = null; try { fis = new FileInputStream(new File(remote)); Util.copyStream(fis, p.getOut()); return null; } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(p.getOut()); } } }); return p.getIn(); }
/** * Reads this file. */ public InputStream read() throws IOException { if(channel==null) return new FileInputStream(new File(remote)); final Pipe p = Pipe.createRemoteToLocal(); channel.callAsync(new Callable<Void,IOException>() { public Void call() throws IOException { FileInputStream fis=null; try { fis = new FileInputStream(new File(remote)); Util.copyStream(fis,p.getOut()); return null; } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(p.getOut()); } } }); return p.getIn(); }
/** * Reads this file. */ public InputStream read() throws IOException { if(channel==null) return new FileInputStream(new File(remote)); final Pipe p = Pipe.createRemoteToLocal(); channel.callAsync(new Callable<Void,IOException>() { public Void call() throws IOException { FileInputStream fis=null; try { fis = new FileInputStream(new File(remote)); Util.copyStream(fis,p.getOut()); return null; } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(p.getOut()); } } }); return p.getIn(); }
/** * Reads this file. */ public InputStream read() throws IOException, InterruptedException { if(channel==null) { try { return Files.newInputStream(reading(new File(remote)).toPath()); } catch (InvalidPathException e) { throw new IOException(e); } } final Pipe p = Pipe.createRemoteToLocal(); actAsync(new SecureFileCallable<Void>() { private static final long serialVersionUID = 1L; @Override public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { try (InputStream fis = Files.newInputStream(reading(f).toPath()); OutputStream out = p.getOut()) { org.apache.commons.io.IOUtils.copy(fis, out); } catch (InvalidPathException e) { p.error(new IOException(e)); } catch (Exception x) { p.error(x); } return null; } }); return p.getIn(); }
final Pipe p = Pipe.createRemoteToLocal(); actAsync(new SecureFileCallable<Void>() { private static final long serialVersionUID = 1L;
@Override public Channel launchChannel(String[] cmd, OutputStream err, FilePath _workDir, Map<String,String> envOverrides) throws IOException, InterruptedException { printCommandLine(cmd, _workDir); Pipe out = Pipe.createRemoteToLocal(); final String workDir = _workDir==null ? null : _workDir.getRemote(); OutputStream os = getChannel().call(new RemoteChannelLaunchCallable(cmd, out, err, workDir, envOverrides)); return new Channel("remotely launched channel on "+channel, Computer.threadPoolForRemoting, out.getIn(), new BufferedOutputStream(os)); }
public Channel launchChannel(String[] cmd, OutputStream err, FilePath _workDir, Map<String,String> envOverrides) throws IOException, InterruptedException { printCommandLine(cmd, _workDir); Pipe out = Pipe.createRemoteToLocal(); final String workDir = _workDir==null ? null : _workDir.getRemote(); OutputStream os = getChannel().call(new RemoteChannelLaunchCallable(cmd, out, err, workDir, envOverrides)); return new Channel("remotely launched channel on "+channel, Computer.threadPoolForRemoting, out.getIn(), new BufferedOutputStream(os)); }
public Channel launchChannel(String[] cmd, OutputStream err, FilePath _workDir, Map<String,String> envOverrides) throws IOException, InterruptedException { printCommandLine(cmd, _workDir); Pipe out = Pipe.createRemoteToLocal(); final String workDir = _workDir==null ? null : _workDir.getRemote(); OutputStream os = getChannel().call(new RemoteChannelLaunchCallable(cmd, out, err, workDir, envOverrides)); return new Channel("remotely launched channel on "+channel, Computer.threadPoolForRemoting, out.getIn(), new BufferedOutputStream(os)); }
public Channel launchChannel(String[] cmd, OutputStream err, FilePath _workDir, Map<String,String> envOverrides) throws IOException, InterruptedException { printCommandLine(cmd, _workDir); Pipe out = Pipe.createRemoteToLocal(); final String workDir = _workDir==null ? null : _workDir.getRemote(); OutputStream os = getChannel().call(new RemoteChannelLaunchCallable(cmd, out, err, workDir, envOverrides)); return new Channel("remotely launched channel on "+channel, Computer.threadPoolForRemoting, out.getIn(), new BufferedOutputStream(os)); }
public Channel launchChannel(String[] cmd, OutputStream err, FilePath _workDir, Map<String, String> envOverrides) throws IOException, InterruptedException { printCommandLine(cmd, _workDir); Pipe out = Pipe.createRemoteToLocal(); final String workDir = _workDir == null ? null : _workDir.getRemote(); OutputStream os = getChannel().call(new RemoteChannelLaunchCallable(cmd, out, err, workDir, envOverrides)); return new Channel("remotely launched channel on " + channel, Computer.threadPoolForRemoting, out.getIn(), new BufferedOutputStream(os)); }
/** * Test the "remote-write local-read" pipe. */ public void testRemoteWrite() throws Exception { Pipe p = Pipe.createRemoteToLocal(); Future<Integer> f = channel.callAsync(new WritingCallable(p)); read(p); int r = f.get(); System.out.println("result=" + r); assertEquals(5,r); }
final Pipe pipe = Pipe.createRemoteToLocal();
/** * Have the reader close the read end of the pipe while the writer is still writing. * The writer should pick up a failure. */ @Bug(8592) @For(Pipe.class) public void testReaderCloseWhileWriterIsStillWriting() throws Exception { final Pipe p = Pipe.createRemoteToLocal(); final Future<Void> f = channel.callAsync(new InfiniteWriter(p)); final InputStream in = p.getIn(); assertEquals(in.read(), 0); in.close(); try { f.get(); fail(); } catch (ExecutionException e) { // should have resulted in an IOException if (!(e.getCause() instanceof IOException)) { e.printStackTrace(); fail(); } } }
} else { final Pipe pipe = Pipe.createRemoteToLocal();