java ftps test

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) {
  }
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值