求助在java中通过ftp方式上传文件的可执行代码

解决方案 »

  1.   

    private void sendBatchViaFTP() {
    FileTransferClient client = new FileTransferClient();
    try {
    File file = new File(path);
    File[] files = file.listFiles(filter);
    client.setRemoteHost(ftpHost);
    client.setRemotePort(ftpPort);
    client.setUserName(ftpUser);
    client.setPassword(ftpPwd);
    client.connect();
    client.changeDirectory(ftpRemotePath);
    for (int i = 0; i < files.length; i++) {
    client.uploadFile(files[i].getAbsolutePath(), files[i]
    .getName());
    }
    } catch (Exception e) {
    logger.error("上传出错:" + e.getMessage(), e);
    } finally {
    if (client != null) {
    try {
    client.disconnect();
    } catch (Exception e) {
    logger.error("与FTP服务器断连出错", e);
    }
    }
    }
    }
    用了第三方的包
    edtftpj.jar
    http://www.enterprisedt.com/products/edtftpj/