Package com.sshtools.j2ssh.subsystem

Examples of com.sshtools.j2ssh.subsystem.SubsystemMessage


     *
     * @throws IOException
     */
    public synchronized FileAttributes getAttributes(String path)
        throws IOException {
        SubsystemMessage msg;
        UnsignedInteger32 requestId = nextRequestId();
        msg = new SshFxpStat(requestId, path);
        sendMessage(msg);

        try {
            SubsystemMessage reply = messageStore.getMessage(requestId);

            if (reply instanceof SshFxpAttrs) {
                return ((SshFxpAttrs) reply).getAttributes();
            } else if (reply instanceof SshFxpStatus) {
                throw new IOException(((SshFxpStatus) reply).getErrorMessage());
            } else {
                throw new IOException("Unexpected server response " +
                    reply.getMessageName());
            }
        } catch (InterruptedException ex) {
            throw new IOException("The thread was interrupted");
        }
    }
View Full Code Here


     *
     * @throws IOException
     */
    public synchronized FileAttributes getAttributes(SftpFile file)
        throws IOException {
        SubsystemMessage msg;
        UnsignedInteger32 requestId = nextRequestId();

        if (!isValidHandle(file.getHandle())) {
            msg = new SshFxpStat(requestId, file.getAbsolutePath());
        } else {
            msg = new SshFxpFStat(requestId, file.getHandle());
        }

        sendMessage(msg);

        try {
            SubsystemMessage reply = messageStore.getMessage(requestId);

            if (reply instanceof SshFxpAttrs) {
                return ((SshFxpAttrs) reply).getAttributes();
            } else if (reply instanceof SshFxpStatus) {
                throw new IOException(((SshFxpStatus) reply).getErrorMessage());
            } else {
                throw new IOException("Unexpected server response " +
                    reply.getMessageName());
            }
        } catch (InterruptedException ex) {
            throw new IOException("The thread was interrupted");
        }
    }
View Full Code Here

        SshFxpRead msg = new SshFxpRead(requestId, handle, offset,
                new UnsignedInteger32(len));
        sendMessage(msg);

        try {
            SubsystemMessage reply = messageStore.getMessage(requestId);

            if (reply instanceof SshFxpData) {
                byte[] msgdata = ((SshFxpData) reply).getData();
                System.arraycopy(msgdata, 0, output, off, msgdata.length);

                return msgdata.length;
            } else if (reply instanceof SshFxpStatus) {
                SshFxpStatus status = (SshFxpStatus) reply;

                if (status.getErrorCode().intValue() == SshFxpStatus.STATUS_FX_EOF) {
                    return -1;
                } else {
                    throw new IOException(((SshFxpStatus) reply).getErrorMessage());
                }
            } else {
                throw new IOException("Unexpected server response " +
                    reply.getMessageName());
            }
        } catch (InterruptedException ex) {
            throw new IOException("The thread was interrupted");
        }
    }
View Full Code Here

     * @throws IOException
     */
    public synchronized void createSymbolicLink(String targetpath,
        String linkpath) throws IOException {
        UnsignedInteger32 requestId = nextRequestId();
        SubsystemMessage msg = new SshFxpSymlink(requestId, targetpath, linkpath);
        sendMessage(msg);
        getOKRequestStatus(requestId);
    }
View Full Code Here

     * @throws IOException
     */
    public synchronized String getSymbolicLinkTarget(String linkpath)
        throws IOException {
        UnsignedInteger32 requestId = nextRequestId();
        SubsystemMessage msg = new SshFxpReadlink(requestId, linkpath);
        sendMessage(msg);

        try {
            SubsystemMessage reply = messageStore.getMessage(requestId);

            if (reply instanceof SshFxpName) {
                SftpFile[] files = ((SshFxpName) reply).getFiles();

                if (files.length != 1) {
                    throw new IOException(
                        "Server responded to SSH_FXP_REALLINK with too many files!");
                }

                return files[0].getAbsolutePath();
            } else if (reply instanceof SshFxpStatus) {
                throw new IOException(((SshFxpStatus) reply).getErrorMessage());
            } else {
                throw new IOException("Unexpected server response " +
                    reply.getMessageName());
            }
        } catch (InterruptedException ex) {
            throw new IOException("The thread was interrupted");
        }
    }
View Full Code Here

     * @throws IOException
     */
    public synchronized void setAttributes(String path, FileAttributes attrs)
        throws IOException {
        UnsignedInteger32 requestId = nextRequestId();
        SubsystemMessage msg = new SshFxpSetStat(requestId, path, attrs);
        sendMessage(msg);
        getOKRequestStatus(requestId);
    }
View Full Code Here

        if (!isValidHandle(file.getHandle())) {
            throw new IOException("The handle is not an open file handle!");
        }

        UnsignedInteger32 requestId = nextRequestId();
        SubsystemMessage msg = new SshFxpFSetStat(requestId, file.getHandle(),
                attrs);
        sendMessage(msg);
        getOKRequestStatus(requestId);
    }
View Full Code Here

        boolean result = false;
        SshFxpInit msg = new SshFxpInit(new UnsignedInteger32(version), null);
        sendMessage(msg);

        // Lets give the sftp subsystem 30 seconds to reply
        SubsystemMessage reply = null;

        for (int i = 0; i < 30; i++) {
            try {
                reply = messageStore.nextMessage(1000);
View Full Code Here

    }

    private byte[] getHandleResponse(UnsignedInteger32 requestId)
        throws IOException {
        try {
            SubsystemMessage reply = messageStore.getMessage(requestId);

            if (reply instanceof SshFxpHandle) {
                byte[] handle = ((SshFxpHandle) reply).getHandle();

                // Add the handle to our managed list
                handles.add(handle);

                return handle;
            } else if (reply instanceof SshFxpStatus) {
                throw new IOException(((SshFxpStatus) reply).getErrorMessage());
            } else {
                throw new IOException("Unexpected server response " +
                    reply.getMessageName());
            }
        } catch (InterruptedException ex) {
            throw new IOException("The thread was interrupted");
        }
    }
View Full Code Here

        try {
            if (log.isDebugEnabled()) {
                log.info("Waiting for response");
            }

            SubsystemMessage reply = messageStore.getMessage(requestId);
            log.info("Received response");

            if (reply instanceof SshFxpStatus) {
                SshFxpStatus status = (SshFxpStatus) reply;

                if (status.getErrorCode().intValue() != SshFxpStatus.STATUS_FX_OK) {
                    throw new IOException(((SshFxpStatus) reply).getErrorMessage());
                }
            } else {
                throw new IOException("Unexpected server response " +
                    reply.getMessageName());
            }
        } catch (InterruptedException ex) {
            throw new IOException("The thread was interrupted");
        }
    }
View Full Code Here

TOP

Related Classes of com.sshtools.j2ssh.subsystem.SubsystemMessage

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.