Package com.trilead.ssh2

Examples of com.trilead.ssh2.SCPClient


    public void testWithGanymede() throws Exception {
        // begin client config
        final Connection conn = new Connection("localhost", port);
        conn.connect(null, 5000, 0);
        conn.authenticateWithPassword("sshd", "sshd");
        final SCPClient scp_client = new SCPClient(conn);
        final Properties props = new Properties();
        props.setProperty("test", "test-passed");
        File f = new File("target/scp/gan");
        Utils.deleteRecursive(f);
        f.mkdirs();
        assertTrue(f.exists());

        String name = "test.properties";
        scp_client.put(toBytes(props, ""), name, "target/scp/gan");
        assertTrue(new File(f, name).exists());
        assertTrue(new File(f, name).delete());

        name = "test2.properties";
        scp_client.put(toBytes(props, ""), name, "target/scp/gan");
        assertTrue(new File(f, name).exists());
        assertTrue(new File(f, name).delete());

        assertTrue(f.delete());
        conn.close();
View Full Code Here


    public void testWithGanymede() throws Exception {
        // begin client config
        final Connection conn = new Connection("localhost", port);
        conn.connect(null, 5000, 0);
        conn.authenticateWithPassword("sshd", "sshd");
        final SCPClient scp_client = new SCPClient(conn);
        final Properties props = new Properties();
        props.setProperty("test", "test-passed");
        File f = new File("target/scp/gan");
        Utils.deleteRecursive(f);
        f.mkdirs();
        assertTrue(f.exists());

        String name = "test.properties";
        scp_client.put(toBytes(props, ""), name, "target/scp/gan");
        assertTrue(new File(f, name).exists());
        assertTrue(new File(f, name).delete());

        name = "test2.properties";
        scp_client.put(toBytes(props, ""), name, "target/scp/gan");
        assertTrue(new File(f, name).exists());
        assertTrue(new File(f, name).delete());

        assertTrue(f.delete());
        conn.close();
View Full Code Here

    public void testWithGanymede() throws Exception {
        // begin client config
        final Connection conn = new Connection("localhost", port);
        conn.connect(null, 5000, 0);
        conn.authenticateWithPassword("sshd", "sshd");
        final SCPClient scp_client = new SCPClient(conn);
        final Properties props = new Properties();
        props.setProperty("test", "test-passed");
        File f = new File("target/scp/gan");
        scp_client.put(toBytes(props, ""), "test.properties", "target/scp/gan");
        assertTrue(f.exists());
        scp_client.put(toBytes(props, ""), "test2.properties", "target/scp/gan");
        assertTrue(f.exists());
        f.delete();
        conn.close();
    }
View Full Code Here

    public void testWithGanymede() throws Exception {
        // begin client config
        final Connection conn = new Connection("localhost", port);
        conn.connect(null, 5000, 0);
        conn.authenticateWithPassword("sshd", "sshd");
        final SCPClient scp_client = new SCPClient(conn);
        final Properties props = new Properties();
        props.setProperty("test", "test-passed");
        scp_client.put(toBytes(props, ""), "test.properties", "target/scp/gan");
        scp_client.put(toBytes(props, ""), "test2.properties", "target/scp/gan");
    }
View Full Code Here

    public void testWithGanymede() throws Exception {
        // begin client config
        final Connection conn = new Connection("localhost", port);
        conn.connect(null, 5000, 0);
        conn.authenticateWithPassword("sshd", "sshd");
        final SCPClient scp_client = new SCPClient(conn);
        final Properties props = new Properties();
        props.setProperty("test", "test-passed");
        File f = new File("target/scp/gan");
        Utils.deleteRecursive(f);
        f.mkdirs();
        assertTrue(f.exists());

        String name = "test.properties";
        scp_client.put(toBytes(props, ""), name, "target/scp/gan");
        assertTrue(new File(f, name).exists());
        assertTrue(new File(f, name).delete());

        name = "test2.properties";
        scp_client.put(toBytes(props, ""), name, "target/scp/gan");
        assertTrue(new File(f, name).exists());
        assertTrue(new File(f, name).delete());

        assertTrue(f.delete());
        conn.close();
View Full Code Here

   */
  public void uploadFile(File localFile, String remoteFile) throws IOException
  {
    logger.debug("upload local file '" + localFile + "' to remote file '" + remoteFile + "'");

    SCPClient scp = conn.createSCPClient();

    OutputStream out = new FileOutputStream(localFile);
    try
    {
      // split remote file in directory
      if (remoteFile.contains("/"))
      {
        String dir = remoteFile.substring(0, remoteFile.lastIndexOf("/"));
        String file = remoteFile.substring(remoteFile.lastIndexOf("/") + 1);
        scp.put(localFile.getAbsolutePath(), file, dir, "0600");
      }
      else
      {
        scp.put(localFile.getAbsolutePath(), remoteFile, "", "0600");
      }
      out.flush();
    }
    finally
    {
View Full Code Here

   */
  public void uploadStringToFile(String string, String remoteFile) throws IOException
  {
    logger.debug("upload string to remote file '" + remoteFile + "'");

    SCPClient scp = conn.createSCPClient();

    if (remoteFile.contains("/"))
    {
      String dir = remoteFile.substring(0, remoteFile.lastIndexOf("/"));
      String file = remoteFile.substring(remoteFile.lastIndexOf("/") + 1);
      scp.put(string.getBytes("UTF-8"), file, dir, "0600");
    }
    else
    {
      scp.put(string.getBytes("UTF-8"), remoteFile, "", "0600");
    }
    logger.debug("upload file complete");

  }
View Full Code Here

   * @throws IOException
   */
  public void downloadFile(String remoteFile, File localFile) throws IOException
  {
    logger.debug("download remote file '" + remoteFile + "' to local file " + localFile);
    SCPClient scp = conn.createSCPClient();

    OutputStream out = new FileOutputStream(localFile);
    try
    {
      scp.get(remoteFile, out);

      out.flush();
    }
    finally
    {
View Full Code Here

  }

  public String downloadFileIntoString(String remoteFile) throws IOException
  {
    logger.debug("download remote file '" + remoteFile);
    SCPClient scp = conn.createSCPClient();

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    scp.get(remoteFile, out);

    return out.toString("UTF-8");
  }
View Full Code Here

  public String downloadFile(String remoteFile) throws IOException
  {
    logger.debug("download remoteFile file '" + remoteFile + "' as string");

    SCPClient scp = conn.createSCPClient();

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    scp.get(remoteFile, out);

    logger.debug("download file complete");

    return out.toString("UTF-8");
  }
View Full Code Here

TOP

Related Classes of com.trilead.ssh2.SCPClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.