日期:2014-05-20 浏览次数:21803 次
public static void main(String[] args) throws IOException { FTPClient ftp = new FTPClient(); int reply; ftp.connect("***.***.***.***"); ftp.login("***", "***"); System.out.println(ftp.getReplyString()); reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); System.err.println("FTP server refused connection."); System.exit(1); } InputStream is = new FileInputStream("d:/1/2/4.txt"); OutputStream os = ftp.storeFileStream("/home/test/4.txt"); byte[] buffer = new byte[1024]; int len; while((len = is.read(buffer)) != -1) { os.write(buffer, 0, len); } is.close(); os.close(); ftp.logout(); if(ftp.isConnected()) { ftp.disconnect(); } }