Package com.jcraft.jsch

Examples of com.jcraft.jsch.ChannelSftp


      template.execute(new SessionCallback<LsEntry, Void>() {

        @Override
        public Void doInSession(Session<LsEntry> session) throws IOException {
          // TODO: avoid DFAs with Spring 4.1 (INT-3412)
          ChannelSftp channel = (ChannelSftp) new DirectFieldAccessor(new DirectFieldAccessor(session)
              .getPropertyValue("targetSession")).getPropertyValue("channel");
          for (int i = 0; i < fileNames.length; i++) {
            try {
              session.remove("si.sftp.sample/" + fileNames[i]);
            }
            catch (IOException e) {}
          }
          try {
            // should be empty
            channel.rmdir("si.sftp.sample");
          }
          catch (SftpException e) {
            fail("Expected remote directory to be empty " + e.getMessage());
          }
          return null;
View Full Code Here


      return template.execute(new SessionCallback<LsEntry, Boolean>() {

        @Override
        public Boolean doInSession(Session<LsEntry> session) throws IOException {
          // TODO: avoid DFAs with Spring 4.1 (INT-3412)
          ChannelSftp channel = (ChannelSftp) new DirectFieldAccessor(new DirectFieldAccessor(session)
              .getPropertyValue("targetSession")).getPropertyValue("channel");
          for (int i = 0; i < fileNames.length; i++) {
            try {
              SftpATTRS stat = channel.stat("si.sftp.sample/" + fileNames[i]);
              if (stat == null) {
                System.out.println("stat returned null for " + fileNames[i]);
                return false;
              }
            }
View Full Code Here

        session.disconnect();
    }

    private static void uploadDemoApplication(Session session)
            throws JSchException, SftpException {
        ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
        sftpChannel.connect();

        String applicationPath = System.getProperty("demo.war");
        if (new File(applicationPath).exists()) {
            sftpChannel.put(applicationPath, "demo.war");
            sftpChannel.disconnect();
        } else {
            sftpChannel.disconnect();
            throw new AssertionError("Demo application not found at "
                    + applicationPath);
        }
    }
View Full Code Here

        String unixPath = "target/scp/out.txt";
        File target = new File(unixPath);
        root.mkdirs();
        assertTrue(root.exists());

        ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
        c.connect();
        c.put(new ByteArrayInputStream("0123456789".getBytes()), unixPath);

        assertTrue(target.exists());
        assertEquals("0123456789", readFile(unixPath));

        OutputStream os = c.put(unixPath, null, ChannelSftp.APPEND, -5);
        os.write("a".getBytes());
        os.close();
        c.disconnect();

        assertTrue(target.exists());
        assertEquals("01234a", readFile(unixPath));

        target.delete();
View Full Code Here

        root.delete();
    }

    @Test
    public void testReadDir() throws Exception {
        ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
        c.connect();
        Vector res = c.ls("target/classes/org/apache/sshd/");
        for (Object f : res) {
            System.out.println(f.toString());
        }
    }
View Full Code Here

        assertTrue(file.exists());
        assertEquals(length, file.length());
    }

    protected String readFile(String path) throws Exception {
        ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
        c.connect();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        InputStream is = c.get(path);
        try {
            byte[] buffer = new byte[256];
            int count;
            while (-1 != (count = is.read(buffer))) {
                bos.write(buffer, 0, count);
            }
        } finally {
            is.close();
        }

        c.disconnect();
        return new String(bos.toByteArray());
    }
View Full Code Here

        c.disconnect();
        return new String(bos.toByteArray());
    }

    protected void sendFile(String path, String data) throws Exception {
        ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
        c.connect();
        c.put(new ByteArrayInputStream(data.getBytes()), path);
        c.disconnect();
    }
View Full Code Here

            {
            }
        });
        session.setPassword(pass);
        session.connect();
        ChannelSftp chan = (ChannelSftp) session.openChannel("sftp");
        chan.connect();
        Vector<?> list = chan.ls(dir);
        Iterator<?> iterList = list.iterator();
        while (iterList.hasNext())
        {
            System.err.println(iterList.next());
        }
        System.err.println("done");
        chan.disconnect();
        session.disconnect();
    }
View Full Code Here

        File target = new File(unixPath);
        Utils.deleteRecursive(root);
        root.mkdirs();
        assertTrue(root.exists());

        ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
        c.connect();
        c.put(new ByteArrayInputStream("0123456789".getBytes()), unixPath);

        assertTrue(target.exists());
        assertEquals("0123456789", readFile(unixPath));

        OutputStream os = c.put(unixPath, null, ChannelSftp.APPEND, -5);
        os.write("a".getBytes());
        os.close();
        c.disconnect();

        assertTrue(target.exists());
        assertEquals("01234a", readFile(unixPath));

        target.delete();
View Full Code Here

        root.delete();
    }

    @Test
    public void testReadDir() throws Exception {
        ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
        c.connect();

        URI url = getClass().getClassLoader().getResource(SshClient.class.getName().replace('.', '/') + ".class").toURI();
        URI base = new File(System.getProperty("user.dir")).getAbsoluteFile().toURI();
        String path = new File(base.relativize(url).getPath()).getParent() + "/";
        path = path.replace('\\', '/');
        Vector res = c.ls(path);
        for (Object f : res) {
            System.out.println(f.toString());
        }
    }
View Full Code Here

TOP

Related Classes of com.jcraft.jsch.ChannelSftp

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.