public static String executeCommandOnFTPServer ( String hostName , Integer port , String userName , String password , String command , String commandArgs ) { String result = null ; if ( StringUtils . isNotBlank ( command ) ) { FTPClient ftpClient = new FTPClient ( ) ; String errorMessage = "Unable to connect and execute %s command with argumments '%s' for FTP server '%s'." ; try { connectAndLoginOnFTPServer ( ftpClient , hostName , port , userName , password ) ; // execute command if ( StringUtils . isBlank ( commandArgs ) ) { ftpClient . sendCommand ( command ) ; } else { ftpClient . sendCommand ( command , commandArgs ) ; } validatResponse ( ftpClient ) ; result = ftpClient . getReplyString ( ) ; } catch ( IOException ex ) { throw new RuntimeException ( String . format ( errorMessage , command , commandArgs , hostName ) , ex ) ; } finally { disconnectAndLogoutFromFTPServer ( ftpClient , hostName ) ; } } return result ; }
Execute command with supplied arguments on the FTP server .