Search in sources :

Example 26 with SFTPException

use of com.trilead.ssh2.SFTPException in project COSMIC-CryoEM-Gateway by cianfrocco-lab.

the class SFTPFileHandler method getInputStream.

public InputStream getInputStream(String fileName) throws Exception {
    Connection conn = getConnection();
    SFTPv3Client client = null;
    try {
        client = new SFTPv3Client(conn);
        return new SFTPInputStream(conn, client, fileName);
    } catch (SFTPException sftpErr) {
        if (client != null) {
            client.close();
        }
        conn.close();
        // we want to produce behavior consistent with the java.io package, so
        // that consumers can have a uniform way of handling exceptions
        m_log.debug("Filename=" + fileName + ", " + sftpErr.getServerErrorMessage() + ": " + sftpErr.getServerErrorCodeVerbose());
        if (sftpErr.getServerErrorCode() == 2) {
            throw new FileNotFoundException(fileName);
        } else {
            throw sftpErr;
        }
    } catch (IOException ioErr) {
        if (client != null)
            client.close();
        conn.close();
        throw ioErr;
    }
}
Also used : Connection(com.trilead.ssh2.Connection) FileNotFoundException(java.io.FileNotFoundException) SFTPv3Client(com.trilead.ssh2.SFTPv3Client) IOException(java.io.IOException) SFTPException(com.trilead.ssh2.SFTPException)

Aggregations

TypesReader (com.trilead.ssh2.packets.TypesReader)20 TypesWriter (com.trilead.ssh2.packets.TypesWriter)18 IOException (java.io.IOException)11 NoSuchFileSftpException (com.jn.agileway.ssh.client.sftp.exception.NoSuchFileSftpException)3 SftpException (com.jn.agileway.ssh.client.sftp.exception.SftpException)3 SFTPException (com.trilead.ssh2.SFTPException)3 ResponseStatusCode (com.jn.agileway.ssh.client.sftp.ResponseStatusCode)2 Connection (com.trilead.ssh2.Connection)2 SFTPv3Client (com.trilead.ssh2.SFTPv3Client)2 Vector (java.util.Vector)2 SFTPException (ch.ethz.ssh2.SFTPException)1 FileAttrs (com.jn.agileway.ssh.client.sftp.attrs.FileAttrs)1 FileMode (com.jn.agileway.ssh.client.sftp.attrs.FileMode)1 SFTPv3FileAttributes (com.trilead.ssh2.SFTPv3FileAttributes)1 SFTPv3FileHandle (com.trilead.ssh2.SFTPv3FileHandle)1 FileNotFoundException (java.io.FileNotFoundException)1