java ftp怎么实现java ftp方式的断点续传 java ftp怎么实现java ftp方式的断点续传?我是用:rivate FtpClient aftp;这个对象的怎么断点续传知道吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一般断点续传的原理是用RandomAccessFile来访问需要传递的文件,然后因为这个类可以根据一个long值去从文件的某一点开始读写。所以你每次传的时候只要记住传到了什么位置,下次就继续传。 import org.apache.commons.net.ftp.FTPClient;import org.apache.commons.net.ftp.FTPReply;import java.io.*;public class MyFTP { private FTPClient ftp = new FTPClient(); public MyFTP() { ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); } public boolean connect(String hostname, int port, String username, String password) throws IOException { ftp.connect(hostname, port); if (FTPReply.isPositiveCompletion(ftp.getReplyCode())) { if (ftp.login(username, password)) { return true; } } disconnect(); return false; } public boolean download(String remote, String local) throws IOException { ftp.enterLocalPassiveMode(); boolean result; File f = new File(local); if (f.exists()) { OutputStream out = new FileOutputStream(f, true); ftp.setRestartOffset(f.length()); result = ftp.retrieveFile(remote, out); out.close(); } else { OutputStream out = new FileOutputStream(f); result = ftp.retrieveFile(remote, out); out.close(); } return result; } public void disconnect() throws IOException { if (ftp.isConnected()) { ftp.disconnect(); } }} 同意 : jFresH_MaN(Contributing to Eclipse) 的观点RandomAccessFile在这里很有用 用了RandomAccessFile,设置好当前起始地点后,直接传就可以续传了吗?还是说要对ftp对象设置什么属性 用socket向ftp服务器发送rest 1000命令,再发送pasv命令打开被动模式,接收新通道的数据后打开通道,在原通道中发送retr [文件名],ftp服务器就通过新通道从请求文件的1000个字符处传文件了 首先要ftp服务器支持 javamail 求助:java与MSSQL数据库的连接疑问 java 中线程池问题???? 用Java或者在jsp页面中不知道这种下拉框怎么做? 请问广州java程序员(应届)工资估计是多少? 编了一个动画程序,老出现错误,请教高手! 100求jxl.*包!!_______JAVA操作EXCEL文件 有对输入法感兴趣的吗? 哪里有jbuilder6下载!!!快快 有哪位大神指导下什么情况(或那个部分)下jvm需要重启电脑才会释放缓存 大伙儿帮忙看看谢啦~~~~~~java包的问题! 跪求答案,请问哪个大哥大姐能帮我做个题目,用JAVA编程,再过3天就要考的,谢谢啊~~
import org.apache.commons.net.ftp.FTPReply;import java.io.*;public class MyFTP {
private FTPClient ftp = new FTPClient(); public MyFTP() {
ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
} public boolean connect(String hostname, int port, String username, String password) throws IOException {
ftp.connect(hostname, port);
if (FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
if (ftp.login(username, password)) {
return true;
}
}
disconnect();
return false;
} public boolean download(String remote, String local) throws IOException {
ftp.enterLocalPassiveMode();
boolean result;
File f = new File(local);
if (f.exists()) {
OutputStream out = new FileOutputStream(f, true);
ftp.setRestartOffset(f.length());
result = ftp.retrieveFile(remote, out);
out.close();
} else {
OutputStream out = new FileOutputStream(f);
result = ftp.retrieveFile(remote, out);
out.close();
}
return result;
} public void disconnect() throws IOException {
if (ftp.isConnected()) {
ftp.disconnect();
}
}
}
RandomAccessFile在这里很有用