當前位置: 首頁>>代碼示例>>Java>>正文


Java ChannelExec.getOutputStream方法代碼示例

本文整理匯總了Java中com.jcraft.jsch.ChannelExec.getOutputStream方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelExec.getOutputStream方法的具體用法?Java ChannelExec.getOutputStream怎麽用?Java ChannelExec.getOutputStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.jcraft.jsch.ChannelExec的用法示例。


在下文中一共展示了ChannelExec.getOutputStream方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: upload

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
@Override
public void upload(Path file, String remotePath)
{
    Session session = null;
    try {
        session = createSession();
        LOGGER.info("Uploading {} onto {}@{}:{}:{}", file, session.getUserName(), session.getHost(), session.getPort(), remotePath);
        ChannelExec channel = (ChannelExec) session.openChannel("exec");
        String command = "scp -t " + remotePath;
        channel.setCommand(command);

        OutputStream out = channel.getOutputStream();
        InputStream in = channel.getInputStream();

        sendSCPFile(file, channel, in, out);
    }
    catch (JSchException | IOException exception) {
        Throwables.propagate(exception);
    }
    finally {
        if (session != null) { session.disconnect(); }
    }
}
 
開發者ID:prestodb,項目名稱:tempto,代碼行數:24,代碼來源:JSchSshClient.java

示例2: testExec

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
@Test(timeout = 5000)
public void testExec(TestContext context) throws Exception {
  startShell();
  Session session = createSession("paulo", "secret", false);
  session.connect();
  ChannelExec channel = (ChannelExec) session.openChannel("exec");
  channel.setCommand("the-command arg1 arg2");
  channel.connect();
  InputStream in = channel.getInputStream();
  StringBuilder input = new StringBuilder();
  while (!input.toString().equals("the_output")) {
    int a = in.read();
    if (a == -1) {
      break;
    }
    input.append((char)a);
  }
  OutputStream out = channel.getOutputStream();
  out.write("the_input".getBytes());
  out.flush();
  while (channel.isConnected()) {
    Thread.sleep(1);
  }
  assertEquals(2, channel.getExitStatus());
  session.disconnect();
}
 
開發者ID:vert-x3,項目名稱:vertx-shell,代碼行數:27,代碼來源:SSHTestBase.java

示例3: scpPut

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
@Override
public OutputStream scpPut(String remoteFilePath, long length, String mode) throws Throwable {

    open();

    if (!Pattern.matches("\\d{4}", mode)) {
        throw new IllegalArgumentException("Invalid file mode: " + mode);
    }

    String dir = PathUtil.getParentDirectory(remoteFilePath);
    String fileName = PathUtil.getFileName(remoteFilePath);

    // exec 'scp -t -d remoteTargetDirectory' remotely
    String command = "scp -t -d \"" + dir + "\"";
    final ChannelExec channel = (ChannelExec) _jschSession.openChannel("exec");
    ((ChannelExec) channel).setCommand(command);

    // get I/O streams for remote scp
    OutputStream out = channel.getOutputStream();
    final InputStream in = channel.getInputStream();

    channel.connect();

    return new ScpOutputStream(channel, in, out, new FileInfo(mode, length, fileName));

}
 
開發者ID:uom-daris,項目名稱:daris,代碼行數:27,代碼來源:JSchSession.java

示例4: write

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
private void write(ChannelExec c, String name, InputStream data, ScpConfiguration cfg) throws IOException {
	OutputStream os = c.getOutputStream();
	InputStream is = c.getInputStream();

	try {
		writeFile(name, data, os, is, cfg);
	} finally {
		IOHelper.close(is, os);
	}
}
 
開發者ID:InitiumIo,項目名稱:camel-jsch,代碼行數:11,代碼來源:ScpOperations.java

示例5: startCommand

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
/**
 * Starts the specified command (executable + params) on the specified ExecutionEnvironment.
 *
 * @param env - environment to execute in
 * @param command - executable + params to execute
 * @param params - (optional) channel params. May be null.
 * @return I/O streams and opened execution JSch channel. Never returns NULL.
 * @throws IOException - if unable to aquire an execution channel
 * @throws JSchException - if JSch exception occured
 * @throws InterruptedException - if the thread was interrupted
 */
public static ChannelStreams startCommand(final ExecutionEnvironment env, final String command, final ChannelParams params)
        throws IOException, JSchException, InterruptedException {

    JSchWorker<ChannelStreams> worker = new JSchWorker<ChannelStreams>() {

        @Override
        public ChannelStreams call() throws JSchException, IOException, InterruptedException {
            ChannelExec echannel = (ChannelExec) ConnectionManagerAccessor.getDefault().openAndAcquireChannel(env, "exec", true); // NOI18N

            if (echannel == null) {
                throw new IOException("Cannot open exec channel on " + env + " for " + command); // NOI18N
            }

            echannel.setCommand(command);
            echannel.setXForwarding(params == null ? false : params.x11forward);
            InputStream is = echannel.getInputStream();
            InputStream es = echannel.getErrStream();
            OutputStream os = new ProtectedOutputStream(echannel, echannel.getOutputStream());
            Authentication auth = Authentication.getFor(env);
            echannel.connect(auth.getTimeout() * 1000);
            return new ChannelStreams(echannel, is, es, os);
        }

        @Override
        public String toString() {
            return command;
        }
    };

    return start(worker, env, 2);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:43,代碼來源:JschSupport.java

示例6: write

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
private void write(ChannelExec c, String name, InputStream data, ScpConfiguration cfg) throws IOException {
    OutputStream os = c.getOutputStream();
    InputStream is = c.getInputStream();

    try {
        writeFile(name, data, os, is, cfg);
    } finally {
        IOHelper.close(is, os);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:11,代碼來源:ScpOperations.java

示例7: sessionConnectGenerateChannel

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
/**
  * Session connect generate channel.
  *
  * @param session
  *            the session
  * @return the channel
  * @throws JSchException
  *             the j sch exception
  */
 public Channel sessionConnectGenerateChannel(Session session)
         throws JSchException {
 	// set timeout
     session.connect(sshMeta.getSshConnectionTimeoutMillis());
     
     ChannelExec channel = (ChannelExec) session.openChannel("exec");
     channel.setCommand(sshMeta.getCommandLine());

     // if run as super user, assuming the input stream expecting a password
     if (sshMeta.isRunAsSuperUser()) {
     	try {
             channel.setInputStream(null, true);

             OutputStream out = channel.getOutputStream();
             channel.setOutputStream(System.out, true);
             channel.setExtOutputStream(System.err, true);
             channel.setPty(true);
             channel.connect();
             
          out.write((sshMeta.getPassword()+"\n").getBytes());
          out.flush();
} catch (IOException e) {
	logger.error("error in sessionConnectGenerateChannel for super user", e);
}
     } else {
     	channel.setInputStream(null);
     	channel.connect();
     }

     return channel;

 }
 
開發者ID:eBay,項目名稱:parallec,代碼行數:42,代碼來源:SshProvider.java

示例8: JSchCliProcess

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
JSchCliProcess(Session session, ChannelExec channel)
        throws IOException
{
    super(channel.getInputStream(), channel.getErrStream(), channel.getOutputStream());
    this.session = session;
    this.channel = channel;
}
 
開發者ID:prestodb,項目名稱:tempto,代碼行數:8,代碼來源:JSchCliProcess.java

示例9: create

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
@Override
public ExecutableChannel create() throws Exception
{
    // http://stackoverflow.com/questions/6265278/whats-the-exact-differences-between-jsch-channelexec-and-channelshell
    this.session = acquire(SshConnection.builder().from(JschSshClient.this.connection).sessionTimeout(0).build());
    executor = (ChannelExec) session.openChannel("exec");
    executor.setCommand(command);

    executor.setErrStream(new ByteArrayOutputStream());
    
    InputStream inputStream = executor.getInputStream();
    InputStream errStream = executor.getErrStream();
    OutputStream outStream = executor.getOutputStream();
    
    executor.connect();

    return new ExecutableChannel(outStream, inputStream, errStream, new Supplier<Integer>()
    {
        @Override
        public Integer get()
        {
            int exitStatus = executor.getExitStatus();
            return exitStatus != -1 ? exitStatus : null;
        }

    }, new Closeable()
    {
        @Override
        public void close() throws IOException
        {
            clear();
        }
    });
}
 
開發者ID:alessandroleite,項目名稱:dohko,代碼行數:35,代碼來源:JschSshClient.java

示例10: execute

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
void execute(Session sshSession) throws SshException
{   
  if (this.scpFile == null)
  {
    throw new SshException("scpFile property has not been set and is null" ,
        new NullPointerException());
  }
  
  InputStream in = null;
  OutputStream out = null;
  InputStream fis = null; 
  ChannelExec channel = null;
  
  try
  {
    try
    {
      final String cmd = SCP_UPLOAD_COMMAND + this.scpFile.getRemotePath();        
      
      channel = this.connectToChannel(sshSession,cmd);
      fis = new FileInputStream(scpFile.getLocalFile());
      in = channel.getInputStream();
      out = channel.getOutputStream();

      if (checkAck(in) != 0)
      {
        throw new SshException("Acknowledgement check failed: Initializing " 
            + "session returned a status code other than 0");
      }
      
      sendFileSizeAndRemotePath(scpFile, out);
      
      if (checkAck(in) != 0)
      {
        throw new SshException("Scp upload failed. Reason: sending filesize "
            + "and filename returned a status code other than 0.");
      }
   
      sendPayloadToServer(out, fis);
      sendEOFToServer(out);
      
      if (checkAck(in) != 0)
      {
        throw new SshException("Scp upload failed.  Reason: sending the  " 
        		+ " file payload resulted a status code other than 0");
      }      
    }
    finally
    {
      if (out != null)
        out.close();
      if (in != null)
        in.close();
      if (fis != null)
        fis.close();
      if (channel != null)
        channel.disconnect();
    }
  }
  catch (Exception e)
  {
    throw new SshException(e);      
  }
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:65,代碼來源:ScpUpload.java

示例11: execute

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
void execute(Session sshSession) throws SshException
{
  InputStream in = null;
  OutputStream out = null;
  FileOutputStream fos = null;
  ChannelExec channel = null;
  try
  {
    try
    {
      long fileSize;
      String cmd = SCP_DOWNLOAD_COMMAND + this.scpFile.getRemotePath();

      channel = connectToChannel(sshSession,cmd);        
      fos = new FileOutputStream(scpFile.getLocalFile());
      in = channel.getInputStream();
      out = channel.getOutputStream();
      
      sendAck(out);             
      
      fileSize = getFileSizeFromStream(in);
      skipFileName(in);
      
      sendAck(out);
      
      writePayloadToFile(in,out,fos,fileSize);
    }
    finally
    {
      if (out != null)
        out.close();
      if (in != null)
        in.close();
      if (fos != null)
        fos.close();
      if (channel != null)
        channel.disconnect();
    }
  }
  catch (Exception e)
  {
    throw new SshException(e);
  }
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:45,代碼來源:ScpDownload.java

示例12: scpGet

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
@Override
public InputStream scpGet(String remoteFilePath) throws Throwable {

    open();

    // exec 'scp -f remoteFilePath' remotely
    String command = "scp -f " + remoteFilePath;
    ChannelExec channel = (ChannelExec) _jschSession.openChannel("exec");
    channel.setCommand(command);

    // get I/O streams for remote scp
    OutputStream out = channel.getOutputStream();
    InputStream in = channel.getInputStream();

    channel.connect();

    return new ScpInputStream(channel, in, out);

}
 
開發者ID:uom-daris,項目名稱:daris,代碼行數:20,代碼來源:JSchSession.java

示例13: JschScpClient

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
JschScpClient(JschConnection connection, ChannelExec channel, String remoteBaseDir, String encoding,
        Integer dirMode, Integer fileMode, boolean compress, boolean preserve, boolean verbose) throws Throwable {
    super(connection, channel, remoteBaseDir, encoding, dirMode, fileMode, compress, preserve, verbose);
    _cin = new BufferedInputStream(channel.getInputStream(), 8192);
    _cout = new BufferedOutputStream(channel.getOutputStream());
}
 
開發者ID:uom-daris,項目名稱:daris,代碼行數:7,代碼來源:JschScpClient.java

示例14: scpToRemote

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
public static void scpToRemote(String host, File lfile, String remotePath, TextStream tout) throws JSchException, IOException {
    Session session = getDefaultSession(host);
    ChannelExec channel = (ChannelExec) session.openChannel("exec");
    channel.setCommand("scp -t "+remotePath);

    // get I/O streams for remote scp
    OutputStream out=channel.getOutputStream();
    InputStream in=channel.getInputStream();

    channel.connect();

    if(checkAck(in)!=0){
        System.exit(0);
    }

    // send "C0644 filesize filename", where filename should not include '/'
    long filesize=lfile.length();
    String command="C0644 "+filesize+" " + lfile.getName();
    command+="\n";
    out.write(command.getBytes()); out.flush();
    int ok = checkAck(in);
    if(ok != 0){
        throw new JSchException("checkAck failure, "+ok);
    }
    tout.appendText(String.format("Transferring %d bytes from: %s\n", filesize, lfile.getAbsolutePath()));

    // send a content of lfile
    FileInputStream fis = new FileInputStream(lfile);
    byte[] buf = new byte[1024];
    int len = fis.read(buf, 0, buf.length);
    long transferred = len;
    long tenPct = filesize / 10;
    int count = 0;
    while(len > 0){
        out.write(buf, 0, len);
        len = fis.read(buf, 0, buf.length);
        transferred += len;
        if(transferred >= tenPct) {
            count ++;
            tenPct = transferred + filesize / 10;
            tout.appendText(String.format("%d%%\n", 10*count));
        }
    }
    fis.close();

    // send '\0'
    buf[0]=0;
    out.write(buf, 0, 1);
    out.flush();
    ok = checkAck(in);
    if(ok != 0){
        throw new JSchException("checkAck failure, "+ok);
    }
    out.close();
    channel.disconnect();
    session.disconnect();
}
 
開發者ID:starksm64,項目名稱:RaspberryPiBeaconParser,代碼行數:58,代碼來源:JSchUtils.java

示例15: testSCP

import com.jcraft.jsch.ChannelExec; //導入方法依賴的package包/類
@Test
    public void testSCP() throws Exception {
        session.connect();
        ChannelExec channel = (ChannelExec) session.openChannel("exec");
        channel.setCommand("scp -t /usr/local/bin/ConfigManager-service.jar");

// get I/O streams for remote scp
        OutputStream out=channel.getOutputStream();
        InputStream in=channel.getInputStream();

        channel.connect();

        if(checkAck(in)!=0){
            System.exit(0);
        }

        File lfile = new File("/Users/starksm/Dev/IoT/BLE/RaspberryPiBeaconParser/ConfigManager/build/libs/ConfigManager-service.jar");

        // send "C0644 filesize filename", where filename should not include '/'
        long filesize=lfile.length();
        String command="C0644 "+filesize+" " + lfile.getName();
        /*???
        if(lfile.lastIndexOf('/')>0){
            command+=lfile.substring(lfile.lastIndexOf('/')+1);
        }
        else{
            command+=lfile;
        }
        */
        command+="\n";
        out.write(command.getBytes()); out.flush();
        if(checkAck(in)!=0){
            System.exit(0);
        }

        // send a content of lfile
        FileInputStream fis=new FileInputStream(lfile);
        byte[] buf=new byte[1024];
        while(true){
            int len=fis.read(buf, 0, buf.length);
            if(len<=0) break;
            out.write(buf, 0, len); //out.flush();
        }
        fis.close();

        // send '\0'
        buf[0]=0;
        out.write(buf, 0, 1);
        out.flush();
        if(checkAck(in)!=0){
            throw new IOException("checkAck error");
        }
        out.close();

        channel.disconnect();
        session.disconnect();
}
 
開發者ID:starksm64,項目名稱:RaspberryPiBeaconParser,代碼行數:58,代碼來源:TstJSch.java


注:本文中的com.jcraft.jsch.ChannelExec.getOutputStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。