Package com.jcraft.jsch

Examples of com.jcraft.jsch.ChannelSftp$LsEntrySelector


     *             if any connection problem occurs
     */
    private ChannelSftp getSftpChannel(String pathOrUri) throws IOException {
        Session session = getSession(pathOrUri);
        String host = session.getHost();
        ChannelSftp channel = SshCache.getInstance().getChannelSftp(session);
        if (channel == null) {
            try {
                channel = (ChannelSftp) session.openChannel("sftp");
                channel.connect();
                Message.verbose(":: SFTP :: connected to " + host + "!");
                SshCache.getInstance().attachChannelSftp(session, channel);
            } catch (JSchException e) {
                IOException ex = new IOException(e.getMessage());
                ex.initCause(e);
View Full Code Here


        });
        return session;
    }

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

    /**
     * Fetches file attrs from server.
     */
    private void statSelf() throws Exception
    {
        ChannelSftp channel = fileSystem.getChannel();
        try
        {
            setStat(channel.stat(relPath));
        }
        catch (final SftpException e)
        {
            try
            {
                // maybe the channel has some problems, so recreate the channel and retry
                if (e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE)
                {
                    channel.disconnect();
                    channel = fileSystem.getChannel();
                    setStat(channel.stat(relPath));
                }
                else
                {
                    // Really does not exist
                    attrs = null;
View Full Code Here

     * Creates this file as a folder.
     */
    @Override
    protected void doCreateFolder() throws Exception
    {
        final ChannelSftp channel = fileSystem.getChannel();
        try
        {
            channel.mkdir(relPath);
        }
        finally
        {
            fileSystem.putChannel(channel);
        }
View Full Code Here

     *            them with second precision.
     */
    @Override
    protected boolean doSetLastModifiedTime(final long modtime) throws Exception
    {
        final ChannelSftp channel = fileSystem.getChannel();
        try
        {
            int newMTime = (int) (modtime / 1000L);

            attrs.setACMODTIME(attrs.getATime(), newMTime);
            channel.setStat(relPath, attrs);
        }
        finally
        {
            fileSystem.putChannel(channel);
        }
View Full Code Here

     * Deletes the file.
     */
    @Override
    protected void doDelete() throws Exception
    {
        final ChannelSftp channel = fileSystem.getChannel();
        try
        {
            if (getType() == FileType.FILE)
            {
                channel.rm(relPath);
            }
            else
            {
                channel.rmdir(relPath);
            }
        }
        finally
        {
            fileSystem.putChannel(channel);
View Full Code Here

     * Rename the file.
     */
    @Override
    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

    @Override
    protected FileObject[] doListChildrenResolved() throws Exception
    {
        // List the contents of the folder
        Vector<?> vector = null;
        final ChannelSftp channel = fileSystem.getChannel();

        try
        {
            // try the direct way to list the directory on the server to avoid too many roundtrips
            vector = channel.ls(relPath);
        }
        catch (SftpException e)
        {
            String workingDirectory = null;
            try
            {
                if (relPath != null)
                {
                    workingDirectory = channel.pwd();
                    channel.cd(relPath);
                }
            }
            catch (SftpException ex)
            {
                // VFS-210: seems not to be a directory
                return null;
            }

            SftpException lsEx = null;
            try
            {
                vector = channel.ls(".");
            }
            catch (SftpException ex)
            {
                lsEx = ex;
            }
            finally
            {
                try
                {
                    if (relPath != null)
                    {
                        channel.cd(workingDirectory);
                    }
                }
                catch (SftpException xe)
                {
                    throw new FileSystemException("vfs.provider.sftp/change-work-directory-back.error",
View Full Code Here

    /**
     * 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
            // .... no stream based method with resume???
            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

    protected InputStream doGetInputStream() throws Exception
    {
        // VFS-113: avoid npe
        synchronized (fileSystem)
        {
            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());
                */

                InputStream is;
                try
                {
                    // VFS-210: sftp allows to gather an input stream even from a directory and will
                    // fail on first read. So we need to check the type anyway
                    if (!getType().hasContent())
                    {
                        throw new FileSystemException("vfs.provider/read-not-file.error", getName());
                    }

                    is = channel.get(relPath);
                }
                catch (SftpException e)
                {
                    if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE)
                    {
View Full Code Here

TOP

Related Classes of com.jcraft.jsch.ChannelSftp$LsEntrySelector

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.