Examples of ChannelSftp


Examples of com.jcraft.jsch.ChannelSftp

        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

Examples of com.jcraft.jsch.ChannelSftp

        }
        log("done.\n");
    }

    private void doSingleTransfer() throws IOException, JSchException {
        ChannelSftp channel = openSftpChannel();
        try {
            channel.connect();
            try {
                sendFileToRemote(channel, localFile, remotePath);
            } catch (SftpException e) {
                throw new JSchException(e.toString());
            }
        } finally {
            if (channel != null) {
                channel.disconnect();
            }
        }
    }
View Full Code Here

Examples of com.jcraft.jsch.ChannelSftp

            }
        }
    }

    private void doMultipleTransfer() throws IOException, JSchException {
        ChannelSftp channel = openSftpChannel();
        try {
            channel.connect();

            try {
                channel.cd(remotePath);
                for (Iterator i = directoryList.iterator(); i.hasNext();) {
                    Directory current = (Directory) i.next();
                    sendDirectory(channel, current);
                }
            } catch (SftpException e) {
                throw new JSchException(e.toString());
            }
        } finally {
            if (channel != null) {
                channel.disconnect();
            }
        }
    }
View Full Code Here

Examples of com.jcraft.jsch.ChannelSftp

     * Carry out the transfer.
     * @throws IOException on i/o errors
     * @throws JSchException on errors detected by scp
     */
    public void execute() throws IOException, JSchException {
        ChannelSftp channel = openSftpChannel();
        try {
            channel.connect();
            try {
                SftpATTRS attrs = channel.stat(remoteFile);
                if (attrs.isDir() && !remoteFile.endsWith("/")) {
                    remoteFile = remoteFile + "/";
                }
            } catch (SftpException ee) {
                // Ignored
            }
            getDir(channel, remoteFile, localFile);
        } catch (SftpException e) {
            throw new JSchException(e.toString());
        } finally {
            if (channel != null) {
                channel.disconnect();
            }
        }
        log("done\n");
    }
View Full Code Here

Examples of com.jcraft.jsch.ChannelSftp

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

Examples of com.jcraft.jsch.ChannelSftp

     * 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

Examples of com.jcraft.jsch.ChannelSftp

     *            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

Examples of com.jcraft.jsch.ChannelSftp

     * 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

Examples of com.jcraft.jsch.ChannelSftp

     * 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

Examples of com.jcraft.jsch.ChannelSftp

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