/** * Closes the connection to the FTP server and restores * connection parameters to the default values. * <p> * Calls {@code setSocketFactory(null)} and {@code setServerSocketFactory(null)} * to reset the factories that may have been changed during the session, * e.g. by {@link #execPROT(String)} * @throws IOException If an error occurs while disconnecting. * @since 3.0 */ @Override public void disconnect() throws IOException { super.disconnect(); if (plainSocket != null) { plainSocket.close(); } setSocketFactory(null); setServerSocketFactory(null); }
setSocketFactory(null); setServerSocketFactory(null); } else { setSocketFactory(new FTPSSocketFactory(context)); setServerSocketFactory(new FTPSServerSocketFactory(context)); initSslContext();
@Override public void setSocketFactory(SocketFactory factory) { if (factory == null){ factory = SocketFactory.getDefault(); } if(mySocketFactoryWrapper != null){ factory = mySocketFactoryWrapper.wrap(factory); } super.setSocketFactory(factory); }
/** * I carry out an ftp command. * When a CCC command was carried out, I steep socket and SocketFactory * in a state of not ssl. * @parm command ftp command. * @return server reply. * @throws IOException If an I/O error occurs while either sending * the command. * @see org.apache.commons.net.ftp.FTP#sendCommand(java.lang.String) */ @Override public int sendCommand(String command, String args) throws IOException { int repCode = super.sendCommand(command, args); if (FTPSCommand._commands[FTPSCommand.CCC].equals(command)) { if (FTPReply.COMMAND_OK == repCode) { // TODO Check this - is this necessary at all? _socket_ = planeSocket; setSocketFactory(null); } else { throw new SSLException(getReplyString()); } } return repCode; }
/** * PROT command.</br> * C - Clear</br> * S - Safe(SSL protocol only)</br> * E - Confidential(SSL protocol only)</br> * P - Private * @param prot Data Channel Protection Level. * @throws SSLException If it server reply code not equal "200". * @throws IOException If an I/O error occurs while either sending * the command. */ public void execPROT(String prot) throws SSLException, IOException { if (prot == null) prot = DEFAULT_PROT; if (!checkPROTValue(prot)) throw new IllegalArgumentException(); if (FTPReply.COMMAND_OK != sendCommand( FTPSCommand._commands[FTPSCommand.PROT], prot)) throw new SSLException(getReplyString()); if (DEFAULT_PROT.equals(prot)) { setSocketFactory(null); setServerSocketFactory(null); } else { setSocketFactory(new FTPSSocketFactory(context)); initSslContext(); SSLServerSocketFactory ssf = context.getServerSocketFactory(); setServerSocketFactory(ssf); } }