Search in sources :

Example 6 with TypesWriter

use of com.trilead.ssh2.packets.TypesWriter in project intellij-community by JetBrains.

the class SFTPv3Client method rmdir.

/**
	 * Remove an empty directory. 
	 * 
	 * @param dirName See the {@link SFTPv3Client comment} for the class for more details.
	 * @throws IOException
	 */
public void rmdir(String dirName) throws IOException {
    int req_id = generateNextRequestID();
    TypesWriter tw = new TypesWriter();
    tw.writeString(dirName, charsetName);
    sendMessage(Packet.SSH_FXP_RMDIR, req_id, tw.getBytes());
    expectStatusOKMessage(req_id);
}
Also used : TypesWriter(com.trilead.ssh2.packets.TypesWriter)

Example 7 with TypesWriter

use of com.trilead.ssh2.packets.TypesWriter in project intellij-community by JetBrains.

the class SFTPv3Client method scanDirectory.

private final Vector scanDirectory(byte[] handle) throws IOException {
    Vector files = new Vector();
    while (true) {
        int req_id = generateNextRequestID();
        TypesWriter tw = new TypesWriter();
        tw.writeString(handle, 0, handle.length);
        if (debug != null) {
            debug.println("Sending SSH_FXP_READDIR...");
            debug.flush();
        }
        sendMessage(Packet.SSH_FXP_READDIR, req_id, tw.getBytes());
        /* Some servers send here a packet with size > 34000 */
        /* To whom it may concern: please learn to read the specs. */
        byte[] resp = receiveMessage(65536);
        if (debug != null) {
            debug.println("Got REPLY.");
            debug.flush();
        }
        TypesReader tr = new TypesReader(resp);
        int t = tr.readByte();
        int rep_id = tr.readUINT32();
        if (rep_id != req_id)
            throw new IOException("The server sent an invalid id field.");
        if (t == Packet.SSH_FXP_NAME) {
            int count = tr.readUINT32();
            if (debug != null)
                debug.println("Parsing " + count + " name entries...");
            while (count > 0) {
                SFTPv3DirectoryEntry dirEnt = new SFTPv3DirectoryEntry();
                dirEnt.filename = tr.readString(charsetName);
                dirEnt.longEntry = tr.readString(charsetName);
                dirEnt.attributes = readAttrs(tr);
                files.addElement(dirEnt);
                if (debug != null)
                    debug.println("File: '" + dirEnt.filename + "'");
                count--;
            }
            continue;
        }
        if (t != Packet.SSH_FXP_STATUS)
            throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");
        int errorCode = tr.readUINT32();
        if (errorCode == ErrorCodes.SSH_FX_EOF)
            return files;
        throw new SFTPException(tr.readString(), errorCode);
    }
}
Also used : TypesReader(com.trilead.ssh2.packets.TypesReader) Vector(java.util.Vector) TypesWriter(com.trilead.ssh2.packets.TypesWriter)

Example 8 with TypesWriter

use of com.trilead.ssh2.packets.TypesWriter in project intellij-community by JetBrains.

the class SFTPv3Client method mkdir.

/**
	 * Create a new directory.
	 * 
	 * @param dirName See the {@link SFTPv3Client comment} for the class for more details.
	 * @param posixPermissions the permissions for this directory, e.g., "0700" (remember that
	 *                         this is octal noation). The server will likely apply a umask.
	 * 
	 * @throws IOException
	 */
public void mkdir(String dirName, int posixPermissions) throws IOException {
    int req_id = generateNextRequestID();
    TypesWriter tw = new TypesWriter();
    tw.writeString(dirName, charsetName);
    tw.writeUINT32(AttribFlags.SSH_FILEXFER_ATTR_PERMISSIONS);
    tw.writeUINT32(posixPermissions);
    sendMessage(Packet.SSH_FXP_MKDIR, req_id, tw.getBytes());
    expectStatusOKMessage(req_id);
}
Also used : TypesWriter(com.trilead.ssh2.packets.TypesWriter)

Example 9 with TypesWriter

use of com.trilead.ssh2.packets.TypesWriter in project intellij-community by JetBrains.

the class SFTPv3Client method fsetstat.

/**
	 * 	Modify the attributes of a file. Used for operations such as changing
	 *  the ownership, permissions or access times, as well as for truncating a file.
	 * 
	 * @param handle a SFTPv3FileHandle handle
	 * @param attr A SFTPv3FileAttributes object. Specifies the modifications to be
	 *             made to the attributes of the file. Empty fields will be ignored.
	 * @throws IOException
	 */
public void fsetstat(SFTPv3FileHandle handle, SFTPv3FileAttributes attr) throws IOException {
    checkHandleValidAndOpen(handle);
    int req_id = generateNextRequestID();
    TypesWriter tw = new TypesWriter();
    tw.writeString(handle.fileHandle, 0, handle.fileHandle.length);
    tw.writeBytes(createAttrs(attr));
    if (debug != null) {
        debug.println("Sending SSH_FXP_FSETSTAT...");
        debug.flush();
    }
    sendMessage(Packet.SSH_FXP_FSETSTAT, req_id, tw.getBytes());
    expectStatusOKMessage(req_id);
}
Also used : TypesWriter(com.trilead.ssh2.packets.TypesWriter)

Example 10 with TypesWriter

use of com.trilead.ssh2.packets.TypesWriter in project intellij-community by JetBrains.

the class SFTPv3Client method mv.

/**
	 * Move a file or directory.
	 * 
	 * @param oldPath See the {@link SFTPv3Client comment} for the class for more details.
	 * @param newPath See the {@link SFTPv3Client comment} for the class for more details.
	 * @throws IOException
	 */
public void mv(String oldPath, String newPath) throws IOException {
    int req_id = generateNextRequestID();
    TypesWriter tw = new TypesWriter();
    tw.writeString(oldPath, charsetName);
    tw.writeString(newPath, charsetName);
    sendMessage(Packet.SSH_FXP_RENAME, req_id, tw.getBytes());
    expectStatusOKMessage(req_id);
}
Also used : TypesWriter(com.trilead.ssh2.packets.TypesWriter)

Aggregations

TypesWriter (com.trilead.ssh2.packets.TypesWriter)23 TypesReader (com.trilead.ssh2.packets.TypesReader)10 Vector (java.util.Vector)1