Search in sources :

Example 1 with WrapperSftp

use of gov.sandia.n2a.host.SshFileSystem.WrapperSftp in project n2a by frothga.

the class SshFileSystemProvider method createDirectory.

public void createDirectory(Path dir, FileAttribute<?>... attributes) throws IOException {
    SshPath A = (SshPath) dir;
    String name = A.toAbsolutePath().toString();
    try {
        WrapperSftp sftp = A.getSftp();
        sftp.mkdir(name);
        applyAttributes(A, attributes);
    } catch (SftpException e) {
        // so the following conclusion might not be accurate ...
        if (e.id == ChannelSftp.SSH_FX_FAILURE)
            throw new FileAlreadyExistsException(name);
        throw new IOException(e);
    }
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) SftpException(com.jcraft.jsch.SftpException) IOException(java.io.IOException) WrapperSftp(gov.sandia.n2a.host.SshFileSystem.WrapperSftp)

Example 2 with WrapperSftp

use of gov.sandia.n2a.host.SshFileSystem.WrapperSftp in project n2a by frothga.

the class SshFileSystemProvider method delete.

public void delete(Path path) throws IOException {
    String name = path.toAbsolutePath().toString();
    try {
        WrapperSftp sftp = ((SshPath) path).getSftp();
        // doesn't follow links
        SftpATTRS attributes = sftp.lstat(name);
        if (attributes.isDir())
            sftp.rmdir(name);
        else
            sftp.rm(name);
    } catch (SftpException e) {
        if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE)
            throw new NoSuchFileException(name);
        throw new IOException(e);
    }
}
Also used : SftpATTRS(com.jcraft.jsch.SftpATTRS) SftpException(com.jcraft.jsch.SftpException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) WrapperSftp(gov.sandia.n2a.host.SshFileSystem.WrapperSftp)

Aggregations

SftpException (com.jcraft.jsch.SftpException)2 WrapperSftp (gov.sandia.n2a.host.SshFileSystem.WrapperSftp)2 IOException (java.io.IOException)2 SftpATTRS (com.jcraft.jsch.SftpATTRS)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1