import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; public class FTPClientTest { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { String remoteParent="/x"; String localFile="C:\\tmp\\hijacked_blog\\index.html"; String remoteFile=Math.random()+"index.html"; String hostname="scharf.gr"; String username="scharf.gr"; String password="*****"; FTPClient ftpClient = new FTPClient(); ftpClient.connect(hostname); ftpClient.login(username,password); ftpClient.enterLocalActiveMode(); ftpClient.sendNoOp(); ftpClient.setFileType(FTP.ASCII_FILE_TYPE); ftpClient.changeWorkingDirectory(remoteParent); FileInputStream input = new FileInputStream(localFile); OutputStream output = ftpClient.storeFileStream(remoteFile); long bytes=0; byte[] buffer = new byte[4096]; int readCount; while((readCount = input.read(buffer)) > 0) { bytes+=readCount; output.write(buffer, 0, readCount); } input.close(); output.flush(); output.close(); ftpClient.completePendingCommand(); System.out.println("done"); } }