connHandler.checkConnection();
try { connHandler.checkConnection();
connHandler.checkConnection();
try { connHandler.checkConnection();
private FTPOutputStream(boolean append) throws IOException { super(null); try { // Retrieve a ConnectionHandler and lock it connHandler = (FTPConnectionHandler)ConnectionPool.getConnectionHandler(FTPFile.this, fileURL, true); // Makes sure the connection is started, if not starts it connHandler.checkConnection(); if(append) out = connHandler.ftpClient.appendFileStream(absPath); else out = connHandler.ftpClient.storeFileStream(absPath); // Note: do NOT use storeUniqueFileStream which appends .1 if the file already exists and fails with proftpd if(out==null) throw new IOException(); } catch(IOException e) { if(connHandler!=null) { // Checks if the IOException corresponds to a socket error and in that case, closes the connection connHandler.checkSocketException(e); // Release the lock on the ConnectionHandler if the OutputStream could not be created connHandler.releaseLock(); } // Re-throw IOException throw e; } }
connHandler.checkConnection();
@Override public void mkdir() throws IOException { // Retrieve a ConnectionHandler and lock it FTPConnectionHandler connHandler = (FTPConnectionHandler)ConnectionPool.getConnectionHandler(this, fileURL, true); try { // Makes sure the connection is started, if not starts it connHandler.checkConnection(); connHandler.ftpClient.makeDirectory(absPath); // Throw an IOException if server replied with an error connHandler.checkServerReply(); file.setType(org.apache.commons.net.ftp.FTPFile.DIRECTORY_TYPE); fileExists = true; } catch(IOException e) { // Checks if the IOException corresponds to a socket error and in that case, closes the connection connHandler.checkSocketException(e); // Re-throw IOException throw e; } finally { // Release the lock on the ConnectionHandler connHandler.releaseLock(); } }
/** * Implementation notes: server-to-server renaming will work if the destination file also uses the 'FTP' scheme * and is located on the same host. */ @Override public void renameTo(AbstractFile destFile) throws IOException { // Throw an exception if the file cannot be renamed to the specified destination checkRenamePrerequisites(destFile, false, false); FTPConnectionHandler connHandler = null; try { // Retrieve a ConnectionHandler and lock it connHandler = (FTPConnectionHandler)ConnectionPool.getConnectionHandler(this, fileURL, true); // Makes sure the connection is started, if not starts it connHandler.checkConnection(); if(!connHandler.ftpClient.rename(absPath, destFile.getURL().getPath())) throw new IOException(); } catch(IOException e) { // Checks if the IOException corresponds to a socket error and in that case, closes the connection if(connHandler!=null) connHandler.checkSocketException(e); throw e; } finally { // Release the lock on the ConnectionHandler if(connHandler!=null) connHandler.releaseLock(); } }
@Override public void delete() throws IOException { // Retrieve a ConnectionHandler and lock it FTPConnectionHandler connHandler = (FTPConnectionHandler)ConnectionPool.getConnectionHandler(this, fileURL, true); try { // Makes sure the connection is started, if not starts it connHandler.checkConnection(); if(isDirectory()) connHandler.ftpClient.removeDirectory(absPath); else connHandler.ftpClient.deleteFile(absPath); fileExists = false; // need to set to false since the file is cached // Throw an IOException if server replied with an error connHandler.checkServerReply(); } catch(IOException e) { // Checks if the IOException corresponds to a socket error and in that case, closes the connection connHandler.checkSocketException(e); // Re-throw IOException throw e; } finally { // Release the lock on the ConnectionHandler connHandler.releaseLock(); } }