/** * Checks if file is a directory * * @param sftpClient * @param filename * @return true, if filename is a directory */ public boolean isDirectory( SFTPv3Client sftpClient, String filename ) { try { return sftpClient.stat( filename ).isDirectory(); } catch ( Exception e ) { // Ignore FTP errors } return false; }
/** * Checks if a directory exists * * @param sftpClient * @param directory * @return true, if directory exists */ public boolean sshDirectoryExists( SFTPv3Client sftpClient, String directory ) { try { SFTPv3FileAttributes attributes = sftpClient.stat( directory ); if ( attributes != null ) { return ( attributes.isDirectory() ); } else { return false; } } catch ( Exception e ) { return false; } }
/** * Graceful {@link #stat(String)} that returns null if the path doesn't exist. * * @param path the path * @return the sft pv 3 file attributes * @throws IOException the io exception */ public SFTPv3FileAttributes _stat(String path) throws IOException { try { return stat(path); } catch (SFTPException e) { int c = e.getServerErrorCode(); if (c== ErrorCodes.SSH_FX_NO_SUCH_FILE || c==ErrorCodes.SSH_FX_NO_SUCH_PATH) return null; else throw e; } }