protected void uploadFile ( final FTPClient ftpClient , final String sourceFilePath , final String targetFilePath , final String logPrefix ) throws IOException { log . info ( String . format ( UPLOAD_FILE , logPrefix , sourceFilePath , targetFilePath ) ) ; final File sourceFile = new File ( sourceFilePath ) ; try ( final InputStream is = new FileInputStream ( sourceFile ) ) { ftpClient . changeWorkingDirectory ( targetFilePath ) ; ftpClient . storeFile ( sourceFile . getName ( ) , is ) ; final int replyCode = ftpClient . getReplyCode ( ) ; final String replyMessage = ftpClient . getReplyString ( ) ; if ( isCommandFailed ( replyCode ) ) { log . error ( String . format ( UPLOAD_FILE_REPLY , logPrefix , replyMessage ) ) ; throw new IOException ( "Failed to upload file: " + sourceFilePath ) ; } else { log . info ( String . format ( UPLOAD_FILE_REPLY , logPrefix , replyMessage ) ) ; } } }
Upload a single file to FTP server with the provided FTP client object .