本人用IIS搭建了一个FTP服务器,用JAVA编写了一个定时FTP的程序,测试时使用的多个小文件(2M)测试成功,正式使用时上传60M的文件就出问题,症状如下:上传多个60多M的文件时通常第一个文件可以上传成功,但紧接着程序停止循环,没有任何错误提示的停止在那里,这是什么原因。

解决方案 »

  1.   

    public void FTPFILE() {
    String msg = "";
    String hostname = getFtpSerIp();
    int port = 21;
    String uid = getFtpSerUser();
    String pwd = getFtpSerPsw();
    String RWFileDir = getLocalFileDir();// 文件目录
    String LocalPathCh = getLocalFileDirChild();
    String ServerPath = getFtpFileDir(); // 连接ftp服务器
    FtpApplet ft = new FtpApplet();
    ft.connect(RWFileDir, hostname, port, uid, pwd); // 上传文件
    if (ft.aftp != null) {
    File fdir = new File(RWFileDir);
    String FileName = "";
    File fileup = null;
    int fdirlen = fdir.list().length;
    for (int i = 0; i < fdirlen; i++) {
    FileName = RWFileDir + (fdir.list())[i];
    fileup = new File(FileName);
    if(fileup.isFile() && FileName.lastIndexOf(".zip") > -1 )
    {
    //备份压缩文件
    msg = ft.copyFile(FileName,getLocalFileDirCopy() + fileup.getName());
    ft.log(RWFileDir, msg);//写入日志文件
    System.out.println(msg);
    //上传文件
    ft.uploadFile(RWFileDir, FileName,LocalPathCh,ServerPath);
    }
    }
    fileup = null; // 删除subunsubfromsp目录下已经上传的文件文件
    ft.deleFile(RWFileDir,""); // 断开服务器连接
    ft.stop(RWFileDir);
    }
    }
      

  2.   

    public boolean uploadFile(String RWFileDir, String filepathname,String LocalPath,String FtpPath) {
    boolean result = true;
    String message = "";
    if (aftp != null) {
    System.out.println("正在上传文件" + filepathname + ",请等待....");
    try {
    String fg = new String(LocalPath);
    int index = filepathname.lastIndexOf(fg);
    String filename = filepathname.substring(index + 1);

    File localFile = new File(filepathname); RandomAccessFile sendFile = new RandomAccessFile(filepathname,
    "r");
    // 
    sendFile.seek(0);
    // 改路径上传
    filename = FtpPath + "ftp_"
    + filename.substring(LocalPath.length()-1, filename.length());
    outs = aftp.put(filename);
    outputs = new DataOutputStream(outs);
    while (sendFile.getFilePointer() < sendFile.length()) {
    ch = sendFile.read();
    outputs.write(ch);
    } outs.close();
    sendFile.close(); message = "上传成功--(" + filepathname +  "-->"  + filename +")";
    System.out.println(message);
    log(RWFileDir, message);
    } catch (IOException e) {
    message = "上传失败--(" + filepathname +")";
    System.out.println(message);
    log(RWFileDir, message+e.toString());
    result = false; }
    } else {
    result = false;
    }
    return result;
    }
      

  3.   

    我用sftp传大文件,ftp的没有试过
      

  4.   

    ftp协议上可能没有完全兼容,用serv-u/ftpd试试看啊。很多ftp服务器用ie ftp://user:pass@ip打不开的