protected void connectAndLogin ( ) throws IOException { if ( ! ftpClient . isConnected ( ) ) { ftpClient . connect ( getEndpointConfiguration ( ) . getHost ( ) , getEndpointConfiguration ( ) . getPort ( ) ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Connected to FTP server: " + ftpClient . getReplyString ( ) ) ; } int reply = ftpClient . getReplyCode ( ) ; if ( ! FTPReply . isPositiveCompletion ( reply ) ) { throw new CitrusRuntimeException ( "FTP server refused connection." ) ; } log . info ( "Opened connection to FTP server" ) ; if ( getEndpointConfiguration ( ) . getUser ( ) != null ) { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "Login as user: '%s'" , getEndpointConfiguration ( ) . getUser ( ) ) ) ; } boolean login = ftpClient . login ( getEndpointConfiguration ( ) . getUser ( ) , getEndpointConfiguration ( ) . getPassword ( ) ) ; if ( ! login ) { throw new CitrusRuntimeException ( String . format ( "Failed to login to FTP server using credentials: %s:%s" , getEndpointConfiguration ( ) . getUser ( ) , getEndpointConfiguration ( ) . getPassword ( ) ) ) ; } } if ( getEndpointConfiguration ( ) . isLocalPassiveMode ( ) ) { ftpClient . enterLocalPassiveMode ( ) ; } } }
Opens a new connection and performs login with user name and password if set .