Package com.sshtools.j2ssh.subsystem

Examples of com.sshtools.j2ssh.subsystem.SubsystemMessage


     * @throws InterruptedException
     */
    public synchronized SubsystemMessage getMessage(UnsignedInteger32 requestId)
        throws InterruptedException {
        Iterator it;
        SubsystemMessage msg;

        // If there ae no messages available then wait untill there are.
        while (getState().getValue() == OpenClosedState.OPEN) {
            if (messages.size() > 0) {
                it = messages.iterator();
View Full Code Here


        UnsignedInteger32 requestId = nextRequestId();
        SshFxpReadDir msg = new SshFxpReadDir(requestId, file.getHandle());
        sendMessage(msg);

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

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

                for (int i = 0; i < files.length; i++) {
                    f = new SftpFile(file.getAbsolutePath() + "/" +
                            files[i].getFilename(), files[i].getAttributes());
                    f.setSFTPSubsystem(this);
                    children.add(f);
                }

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

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

     */
    public synchronized SftpFile openDirectory(String path)
        throws IOException {
        String absolutePath = getAbsolutePath(path);
        UnsignedInteger32 requestId = nextRequestId();
        SubsystemMessage msg = new SshFxpOpenDir(requestId, absolutePath);
        sendMessage(msg);

        byte[] handle = getHandleResponse(requestId);
        requestId = nextRequestId();
        msg = new SshFxpStat(requestId, absolutePath);
        sendMessage(msg);

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

            if (reply instanceof SshFxpAttrs) {
                SftpFile file = new SftpFile(absolutePath,
                        ((SshFxpAttrs) reply).getAttributes());
                file.setHandle(handle);
                file.setSFTPSubsystem(this);

                return file;
            } 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 String getAbsolutePath(String path)
        throws IOException {
        UnsignedInteger32 requestId = nextRequestId();
        SubsystemMessage msg = new SshFxpRealPath(requestId, path);
        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_REALPATH 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

        if (attrs == null) {
            attrs = new FileAttributes();
        }

        UnsignedInteger32 requestId = nextRequestId();
        SubsystemMessage msg = new SshFxpOpen(requestId, absolutePath,
                new UnsignedInteger32(flags), attrs);
        sendMessage(msg);

        byte[] handle = getHandleResponse(requestId);
        SftpFile file = new SftpFile(absolutePath, null);
View Full Code Here

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

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.