Search in sources :

Example 1 with SFTPv3Client

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

the class SFTPv3Client method canonicalPath.

/**
	 * Have the server canonicalize any given path name to an absolute path.
	 * This is useful for converting path names containing ".." components or
	 * relative pathnames without a leading slash into absolute paths.
	 * 
	 * @param path See the {@link SFTPv3Client comment} for the class for more details.
	 * @return An absolute path.
	 * @throws IOException
	 */
public String canonicalPath(String path) throws IOException {
    int req_id = generateNextRequestID();
    TypesWriter tw = new TypesWriter();
    tw.writeString(path, charsetName);
    if (debug != null) {
        debug.println("Sending SSH_FXP_REALPATH...");
        debug.flush();
    }
    sendMessage(Packet.SSH_FXP_REALPATH, 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_NAME) {
        int count = tr.readUINT32();
        if (count != 1)
            throw new IOException("The server sent an invalid SSH_FXP_NAME packet.");
        return tr.readString(charsetName);
    }
    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 2 with SFTPv3Client

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

the class SFTPv3Client method rm.

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

Example 3 with SFTPv3Client

use of com.trilead.ssh2.SFTPv3Client 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 4 with SFTPv3Client

use of com.trilead.ssh2.SFTPv3Client 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 5 with SFTPv3Client

use of com.trilead.ssh2.SFTPv3Client 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)8 SFTPv3Client (com.trilead.ssh2.SFTPv3Client)6 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)6 KettleException (org.pentaho.di.core.exception.KettleException)6 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)6 Connection (com.trilead.ssh2.Connection)3 SFTPv3DirectoryEntry (com.trilead.ssh2.SFTPv3DirectoryEntry)3 File (java.io.File)3 Pattern (java.util.regex.Pattern)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 Result (org.pentaho.di.core.Result)3 FTPException (com.enterprisedt.net.ftp.FTPException)2 SFTPv3FileHandle (com.trilead.ssh2.SFTPv3FileHandle)2 TypesReader (com.trilead.ssh2.packets.TypesReader)2 IOException (java.io.IOException)2 Matcher (java.util.regex.Matcher)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 HTTPProxyData (com.trilead.ssh2.HTTPProxyData)1 BufferedInputStream (java.io.BufferedInputStream)1 FileOutputStream (java.io.FileOutputStream)1