java ftp怎么实现java ftp方式的断点续传?
我是用:rivate FtpClient aftp;这个对象的怎么断点续传知道吗?

解决方案 »

  1.   

    一般断点续传的原理是用RandomAccessFile来访问需要传递的文件,然后因为这个类可以根据一个long值去从文件的某一点开始读写。所以你每次传的时候只要记住传到了什么位置,下次就继续传。
      

  2.   

    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();
            }
        }
    }
      

  3.   

    同意 : jFresH_MaN(Contributing to Eclipse) 的观点
    RandomAccessFile在这里很有用
      

  4.   

    用了RandomAccessFile,设置好当前起始地点后,直接传就可以续传了吗?还是说要对ftp对象设置什么属性
      

  5.   

    用socket向ftp服务器发送rest 1000命令,再发送pasv命令打开被动模式,接收新通道的数据后打开通道,在原通道中发送retr [文件名],ftp服务器就通过新通道从请求文件的1000个字符处传文件了
      

  6.   

    首先要ftp服务器支持