class JavaTest {
public static void main(String[] args) {
ByteArrayOutputStream Log = new ByteArrayOutputStream();
PrintStream printLog = new PrintStream(Log);
PrintWriter LogPrinter = new PrintWriter(Log);
try {
org.apache.commons.net.ftp.FTPSClient FTPs = new org.apache.commons.net.ftp.FTPSClient(false);
FTPs.addProtocolCommandListener(new org.apache.commons.net.PrintCommandListener(LogPrinter));
FTPs.setDefaultTimeout(10000);
FTPs.connect("ftpstest.forus.com"); // ftp://ftpstest.forus.com 100MB, bandwidth limited, no MkDir, supports FTP Active, and FTPS Active & Passive. Please delete files
FTPs.setSoTimeout(900000); // 15 minutes, a massive file transfer.
FTPs.getReplyCode();
FTPs.execPBSZ(0); // RFC2228 requires that the PBSZ subcommand be issued prior to the PROT subcommand. However, TLS/SSL handles blocking of data, so '0' is the only value accepted.
FTPs.execPROT("P"); // P(rivate) data channel, which needs certs if "Active". E and S: '536 Requested PROT level not supported by mechanism.'. C is default, but has clear text data channel - http://www.nabble.com/TLS-for-FTP-td6645485.html
FTPs.login("ftp_testing","ftp_testing");
FTPs.changeWorkingDirectory("/");
java.io.FileInputStream fileStream = new java.io.FileInputStream("JavaTest.java");
FTPs.setDataTimeout(5000);
FTPs.enterLocalPassiveMode(); // Active is the default, which very few clients can suppart in SSL (firewalls can't detect "PORT" command, and thus cant open/map local port). Active will also require keys/certs.
printLog.println("(call store file...)");
FTPs.storeFile("JavaTest.java", fileStream);
fileStream.close();
FTPs.disconnect();
System.out.println("");
System.out.println("FTP COMMAND LOG:");
System.out.println(Log.toString());
} catch(Exception e) {
}
}
}