try{
ftps.connect(server); System.out.println("Connected to "+server+".");
// After connection attempt, you should check the reply code to verify // success. int reply = ftps.getReplyCode(); if(!FTPReply.isPositiveCompletion(reply)){
ftps.disconnect(); System.err.println("FTP server refused connection."); System.exit(1); } }catch(IOException e){ if(ftps.isConnected()){ try{
ftps.disconnect(); }catch(IOException f){ // do nothing } } System.err.println("Could not connect to server.");
e.printStackTrace(); System.exit(1); }
System.out.println("Remote system is "+ ftps.getSystemName()); if(binaryTransfer)
ftps.setFileType(FTP.BINARY_FILE_TYPE);
// Use passive mode as default because most of us are // behind firewalls these days.
ftps.enterLocalPassiveMode(); if(storeFile){ InputStream input;
input =newFileInputStream(local);
ftps.storeFile(remote, input);
input.close(); }else{ OutputStreamoutput; output=newFileOutputStream(local);
ftps.retrieveFile(remote,output); output.close(); }