Search in sources :

Example 6 with SFTPv3FileAttributes

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

the class SFTPv3Client method statBoth.

private SFTPv3FileAttributes statBoth(String path, int statMethod) throws IOException {
    int req_id = generateNextRequestID();
    TypesWriter tw = new TypesWriter();
    tw.writeString(path, charsetName);
    if (debug != null) {
        debug.println("Sending SSH_FXP_STAT/SSH_FXP_LSTAT...");
        debug.flush();
    }
    sendMessage(statMethod, req_id, tw.getBytes());
    byte[] resp = receiveMessage(34000);
    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_ATTRS) {
        return readAttrs(tr);
    }
    if (t != Packet.SSH_FXP_STATUS)
        throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");
    int errorCode = tr.readUINT32();
    throw new SFTPException(tr.readString(), errorCode);
}
Also used : TypesReader(com.trilead.ssh2.packets.TypesReader) TypesWriter(com.trilead.ssh2.packets.TypesWriter)

Example 7 with SFTPv3FileAttributes

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

the class SFTPv3Client method setstat.

/**
	 *  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 path See the {@link SFTPv3Client comment} for the class for more details.
	 * @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 setstat(String path, SFTPv3FileAttributes attr) throws IOException {
    int req_id = generateNextRequestID();
    TypesWriter tw = new TypesWriter();
    tw.writeString(path, charsetName);
    tw.writeBytes(createAttrs(attr));
    if (debug != null) {
        debug.println("Sending SSH_FXP_SETSTAT...");
        debug.flush();
    }
    sendMessage(Packet.SSH_FXP_SETSTAT, req_id, tw.getBytes());
    expectStatusOKMessage(req_id);
}
Also used : TypesWriter(com.trilead.ssh2.packets.TypesWriter)

Example 8 with SFTPv3FileAttributes

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

the class SFTPv3Client method fstat.

/**
	 * Retrieve the file attributes of an open file.
	 * 
	 * @param handle a SFTPv3FileHandle handle.
	 * @return a SFTPv3FileAttributes object.
	 * @throws IOException
	 */
public SFTPv3FileAttributes fstat(SFTPv3FileHandle handle) throws IOException {
    checkHandleValidAndOpen(handle);
    int req_id = generateNextRequestID();
    TypesWriter tw = new TypesWriter();
    tw.writeString(handle.fileHandle, 0, handle.fileHandle.length);
    if (debug != null) {
        debug.println("Sending SSH_FXP_FSTAT...");
        debug.flush();
    }
    sendMessage(Packet.SSH_FXP_FSTAT, req_id, tw.getBytes());
    byte[] resp = receiveMessage(34000);
    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_ATTRS) {
        return readAttrs(tr);
    }
    if (t != Packet.SSH_FXP_STATUS)
        throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");
    int errorCode = tr.readUINT32();
    throw new SFTPException(tr.readString(), errorCode);
}
Also used : TypesReader(com.trilead.ssh2.packets.TypesReader) TypesWriter(com.trilead.ssh2.packets.TypesWriter)

Example 9 with SFTPv3FileAttributes

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

the class SFTPv3Client method openFile.

private SFTPv3FileHandle openFile(String fileName, int flags, SFTPv3FileAttributes attr) throws IOException {
    int req_id = generateNextRequestID();
    TypesWriter tw = new TypesWriter();
    tw.writeString(fileName, charsetName);
    tw.writeUINT32(flags);
    tw.writeBytes(createAttrs(attr));
    if (debug != null) {
        debug.println("Sending SSH_FXP_OPEN...");
        debug.flush();
    }
    sendMessage(Packet.SSH_FXP_OPEN, req_id, tw.getBytes());
    byte[] resp = receiveMessage(34000);
    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_HANDLE) {
        if (debug != null) {
            debug.println("Got SSH_FXP_HANDLE.");
            debug.flush();
        }
        return new SFTPv3FileHandle(this, tr.readByteString());
    }
    if (t != Packet.SSH_FXP_STATUS)
        throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");
    int errorCode = tr.readUINT32();
    String errorMessage = tr.readString();
    throw new SFTPException(errorMessage, errorCode);
}
Also used : TypesReader(com.trilead.ssh2.packets.TypesReader) TypesWriter(com.trilead.ssh2.packets.TypesWriter)

Example 10 with SFTPv3FileAttributes

use of com.trilead.ssh2.SFTPv3FileAttributes in project Payara by payara.

the class SFTPClient method mkdirs.

/**
 * Makes sure that the directory exists, by creating it if necessary.
 */
public void mkdirs(String path, int posixPermission) throws IOException {
    path = normalizePath(path);
    SFTPv3FileAttributes atts = _stat(path);
    if (atts != null && atts.isDirectory())
        return;
    int idx = path.lastIndexOf("/");
    if (idx > 0)
        mkdirs(path.substring(0, idx), posixPermission);
    try {
        mkdir(path, posixPermission);
    } catch (IOException e) {
        throw new IOException("Failed to mkdir " + path, e);
    }
}
Also used : IOException(java.io.IOException) SFTPv3FileAttributes(com.trilead.ssh2.SFTPv3FileAttributes)

Aggregations

TypesWriter (com.trilead.ssh2.packets.TypesWriter)6 SFTPv3FileAttributes (com.trilead.ssh2.SFTPv3FileAttributes)5 TypesReader (com.trilead.ssh2.packets.TypesReader)3 IOException (java.io.IOException)2 Node (com.sun.enterprise.config.serverbeans.Node)1 Nodes (com.sun.enterprise.config.serverbeans.Nodes)1 WindowsRemoteFile (com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile)1 WindowsRemoteFileSystem (com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem)1 WindowsException (com.sun.enterprise.util.cluster.windows.process.WindowsException)1 SFTPv3DirectoryEntry (com.trilead.ssh2.SFTPv3DirectoryEntry)1 IOException2 (hudson.util.IOException2)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SSHLauncher (org.glassfish.cluster.ssh.launcher.SSHLauncher)1 SFTPClient (org.glassfish.cluster.ssh.sftp.SFTPClient)1 DcomInfo (org.glassfish.cluster.ssh.util.DcomInfo)1