Package com.jcraft.jsch

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
            // .... 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

        /*
        final ChannelSftp channel = fileSystem.getChannel();
        return new SftpOutputStream(channel);
        */

        final ChannelSftp channel = fileSystem.getChannel();
        return new SftpOutputStream(channel, channel.put(relPath));
    }
View Full Code Here

        }

        try
        {
            // Use the pooled channel, or create a new one
            final ChannelSftp channel;
            if (idleChannel != null)
            {
                channel = idleChannel;
                idleChannel = null;
            }
            else
            {
                channel = (ChannelSftp) session.openChannel("sftp");
                channel.connect();

                Boolean userDirIsRoot =
                    SftpFileSystemConfigBuilder.getInstance().getUserDirIsRoot(getFileSystemOptions());
                String workingDirectory = getRootName().getPath();
                if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue()))
                {
                    try
                    {
                        channel.cd(workingDirectory);
                    }
                    catch (SftpException e)
                    {
                        throw new FileSystemException("vfs.provider.sftp/change-work-directory.error",
                            workingDirectory);
View Full Code Here

     * @param session
     *            to connect to
     * @return channelSftp or null if not successful (channel not existent or dead)
     */
    public ChannelSftp getChannelSftp(Session session) throws IOException {
        ChannelSftp channel = null;
        Entry entry = getCacheEntry(session);
        if (entry != null) {
            channel = entry.getChannelSftp();
            if (channel != null && !channel.isConnected()) {
                entry.releaseChannelSftp();
                channel = null;
            }
        }
        return channel;
View Full Code Here

     * @return a fully initialised resource, able to answer to all its methods without needing any
     *         further connection
     */
    public Resource resolveResource(String path) {
        try {
            ChannelSftp c = getSftpChannel(path);
            Collection r = c.ls(path);
            if (r != null) {
                for (Iterator iter = r.iterator(); iter.hasNext();) {
                    Object obj = iter.next();
                    if (obj instanceof LsEntry) {
                        LsEntry entry = (LsEntry) obj;
View Full Code Here

        }
        return new BasicResource(path, false, 0, 0, false);
    }

    public InputStream openStream(SFTPResource resource) throws IOException {
        ChannelSftp c = getSftpChannel(resource.getName());
        try {
            return c.get(resource.getName());
        } catch (SftpException e) {
            e.printStackTrace();
            IOException ex = new IOException("impossible to open stream for " + resource + " on "
                    + getHost() + (e.getMessage() != null ? ": " + e.getMessage() : ""));
            ex.initCause(e);
View Full Code Here

        }
    }

    public void get(String source, File destination) throws IOException {
        fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET);
        ChannelSftp c = getSftpChannel(source);
        try {
            c.get(source, destination.getAbsolutePath(), new MyProgressMonitor());
        } catch (SftpException e) {
            e.printStackTrace();
            IOException ex = new IOException("impossible to get " + source + " on " + getHost()
                    + (e.getMessage() != null ? ": " + e.getMessage() : ""));
            ex.initCause(e);
View Full Code Here

        }
    }

    public void put(File source, String destination, boolean overwrite) throws IOException {
        fireTransferInitiated(getResource(destination), TransferEvent.REQUEST_PUT);
        ChannelSftp c = getSftpChannel(destination);
        try {
            if (!overwrite && checkExistence(destination, c)) {
                throw new IOException("destination file exists and overwrite == true");
            }
            if (destination.indexOf('/') != -1) {
                mkdirs(destination.substring(0, destination.lastIndexOf('/')), c);
            }
            c.put(source.getAbsolutePath(), destination, new MyProgressMonitor());
        } catch (SftpException e) {
            IOException ex = new IOException(e.getMessage());
            ex.initCause(e);
            throw ex;
        }
View Full Code Here

        }
    }

    public List list(String parent) throws IOException {
        try {
            ChannelSftp c = getSftpChannel(parent);
            Collection r = c.ls(parent);
            if (r != null) {
                if (!parent.endsWith("/")) {
                    parent = parent + "/";
                }
                List result = new ArrayList();
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.