protected FtpMessage retrieveFile ( GetCommand command , TestContext context ) { try { String remoteFilePath = context . replaceDynamicContentInString ( command . getFile ( ) . getPath ( ) ) ; String localFilePath = addFileNameToTargetPath ( remoteFilePath , context . replaceDynamicContentInString ( command . getTarget ( ) . getPath ( ) ) ) ; if ( Paths . get ( localFilePath ) . getParent ( ) != null ) { Files . createDirectories ( Paths . get ( localFilePath ) . getParent ( ) ) ; } String dataType = context . replaceDynamicContentInString ( Optional . ofNullable ( command . getFile ( ) . getType ( ) ) . orElse ( DataType . BINARY . name ( ) ) ) ; try ( FileOutputStream localFileOutputStream = new FileOutputStream ( localFilePath ) ) { ftpClient . setFileType ( getFileType ( dataType ) ) ; if ( ! ftpClient . retrieveFile ( remoteFilePath , localFileOutputStream ) ) { throw new CitrusRuntimeException ( "Failed to get file from FTP server. Remote path: " + remoteFilePath + ". Local file path: " + localFilePath + ". FTP reply: " + ftpClient . getReplyString ( ) ) ; } } if ( getEndpointConfiguration ( ) . isAutoReadFiles ( ) ) { String fileContent ; if ( command . getFile ( ) . getType ( ) . equals ( DataType . BINARY . name ( ) ) ) { fileContent = Base64 . encodeBase64String ( FileCopyUtils . copyToByteArray ( FileUtils . getFileResource ( localFilePath ) . getInputStream ( ) ) ) ; } else { fileContent = FileUtils . readToString ( FileUtils . getFileResource ( localFilePath ) ) ; } return FtpMessage . result ( ftpClient . getReplyCode ( ) , ftpClient . getReplyString ( ) , localFilePath , fileContent ) ; } else { return FtpMessage . result ( ftpClient . getReplyCode ( ) , ftpClient . getReplyString ( ) , localFilePath , null ) ; } } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to get file from FTP server" , e ) ; } }
Performs retrieve file operation .