Package com.sshtools.j2ssh.subsystem

Examples of com.sshtools.j2ssh.subsystem.SubsystemMessage


     * @return true if the agent was unlocked, otherwise false
     *
     * @throws IOException if an IO error occurs
     */
    public boolean unlockAgent(String password) throws IOException {
        SubsystemMessage msg = new SshAgentUnlock(password);
        sendMessage(msg);
        msg = readMessage();

        return (msg instanceof SshAgentSuccess);
    }
View Full Code Here


     * @return the random data received
     *
     * @throws IOException if an IO error occurs
     */
    public byte[] getRandomData(int count) throws IOException {
        SubsystemMessage msg = new SshAgentRandom(count);
        sendMessage(msg);
        msg = readMessage();

        if (msg instanceof SshAgentRandomData) {
            return ((SshAgentRandomData) msg).getRandomData();
View Full Code Here

     * @param padding the padding data
     *
     * @throws IOException if an IO error occurs
     */
    public void ping(byte[] padding) throws IOException {
        SubsystemMessage msg = new SshAgentPing(padding);
        sendMessage(msg);
        msg = readMessage();

        if (msg instanceof SshAgentAlive) {
            if (!Arrays.equals(padding, ((SshAgentAlive) msg).getPadding())) {
View Full Code Here

     *
     * @throws IOException if an IO error occurs
     */
    public void deleteKey(SshPublicKey key, String description)
        throws IOException {
        SubsystemMessage msg = new SshAgentDeleteKey(key, description);
        sendMessage(msg);
        msg = readMessage();

        if (!(msg instanceof SshAgentSuccess)) {
            throw new IOException("The agent failed to delete the key");
View Full Code Here

     * Delete all the keys held by the agent.
     *
     * @throws IOException if an IO error occurs
     */
    public void deleteAllKeys() throws IOException {
        SubsystemMessage msg = new SshAgentDeleteAllKeys();
        sendMessage(msg);
        msg = readMessage();

        if (!(msg instanceof SshAgentSuccess)) {
            throw new IOException("The agent failed to delete all keys");
View Full Code Here

            Integer id = new Integer((int) msgdata[0] & 0xFF);

            if (messages.containsKey(id)) {
                Class cls = (Class) messages.get(id);
                SubsystemMessage msg = (SubsystemMessage) cls.newInstance();
                msg.fromByteArray(msgdata);
                log.info("Received message " + msg.getMessageName());

                return msg;
            } else {
                throw new InvalidMessageException("Unrecognised message id " +
                    id.toString());
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

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.