Examples of ChannelSftp


Examples of com.jcraft.jsch.ChannelSftp

  /**
   * Rename the file.
   */
  protected void doRename(FileObject newfile) throws Exception
  {
    final ChannelSftp channel = fileSystem.getChannel();
    try
    {
      channel.rename(relPath, ((SftpFileObject) newfile).relPath);
    }
    finally
    {
      fileSystem.putChannel(channel);
    }
View Full Code Here

Examples of com.jcraft.jsch.ChannelSftp

   */
  protected FileObject[] doListChildrenResolved() throws Exception
  {
    // List the contents of the folder
    final Vector vector;
    final ChannelSftp channel = fileSystem.getChannel();
    try
    {
      vector = channel.ls(relPath);
    }
    finally
    {
      fileSystem.putChannel(channel);
    }
View Full Code Here

Examples of com.jcraft.jsch.ChannelSftp

  /**
   * Creates an input stream to read the file content from.
   */
  InputStream getInputStream(long filePointer) throws IOException
  {
    final ChannelSftp channel = fileSystem.getChannel();
    try
    {
      // hmmm - using the in memory method is soooo much faster ...
      // TODO - Don't read the entire file into memory. Use the
      // stream-based methods on ChannelSftp once they work properly final
      ByteArrayOutputStream outstr = new ByteArrayOutputStream();
      try
      {
        channel.get(getName().getPathDecoded(), outstr, null,
            ChannelSftp.RESUME, filePointer);
      }
      catch (SftpException e)
      {
        throw new FileSystemException(e);
View Full Code Here

Examples of com.jcraft.jsch.ChannelSftp

  /**
   * Creates an input stream to read the file content from.
   */
  protected InputStream doGetInputStream() throws Exception
  {
    final ChannelSftp channel = fileSystem.getChannel();
    try
    {
      // return channel.get(getName().getPath());
      // hmmm - using the in memory method is soooo much faster ...

      // TODO - Don't read the entire file into memory. Use the
      // stream-based methods on ChannelSftp once they work properly
      final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
      channel.get(relPath, outstr);
      outstr.close();
      return new ByteArrayInputStream(outstr.toByteArray());

    }
    finally
View Full Code Here

Examples of com.jcraft.jsch.ChannelSftp

   */
  protected OutputStream doGetOutputStream(boolean bAppend) throws Exception
  {
    // TODO - Don't write the entire file into memory. Use the stream-based
    // methods on ChannelSftp once the work properly
    final ChannelSftp channel = fileSystem.getChannel();
    return new SftpOutputStream(channel);
  }
View Full Code Here

Examples of com.jcraft.jsch.ChannelSftp

        });
        return session;
    }

    public ChannelSftp createChannelSftp(Session session) throws JSchException {
        final ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
        return channel;
    }
View Full Code Here

Examples of com.jcraft.jsch.ChannelSftp

            {
            }
        });
        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

Examples of com.jcraft.jsch.ChannelSftp

        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

Examples of com.jcraft.jsch.ChannelSftp

        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

Examples of com.jcraft.jsch.ChannelSftp

        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
TOP
Copyright © 2018 www.massapi.com. 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.