无论是c++写的程序还是java写的,上传服务器连接上了,文件存放路径和文件名也建立了,
但是到ftp.storeFile(sound, fis);这一步是就走不下去了,查看服务器上的文件大小是0K;
方法是用定时器调用的,而不是页面请求调用;很奇怪的是在公司服务器上和本人自己机器上传都没问题,
就是放到衢州服务器上时出现ftp上传的文件大小是0,在storeFile这一步时停止了;如果是代码问题,在公司服务器上运行正常,如果是衢州服务器问题,在那服务器上用FlashFXP工具上传就没问题;所以很头大,郁闷死了!!!

解决方案 »

  1.   

    public class FtpUploadSound {
    private ISellRecordDao sellRecordDao; private static FTPClient ftp; private static int flag = 0; public void doUpload() {
    String soundsUploadTag = ConfigFilePath
    .configByParaName("soundsUploadTag");
    if (soundsUploadTag != null && soundsUploadTag.equals("0")) {
    List rings = sellRecordDao.getRingoutPut();
    Ringout ring = null;
    String remote = null;
    String local = null;
    String sound = null;
    boolean connectFlag = false;
    for (int i = 0; i < rings.size(); i++) {
    ring = (Ringout) rings.get(i);
    // 第一次进行ftp连接
    if (i == 0) {
    // 修改上传状态
    ConfigFilePath.updateConfigByParaName("soundsUploadTag","1");
    connectFlag = connectFtpServer("202.107.217.46", "sply_1", "qljlyrh",
    21);
    }
    if (connectFlag) {// 连接成功
    remote = getPathStr(ring, 0);
    local = getPathStr(ring, 1);
    sound = ring.getSong();
    if (createDirectory(remote)) {// 创建进入路径
    if (uploadFile(local, remote, sound, ring.getId())) {// 上传录音
    // 更新记录
    String sql = "update ringoutput set flag=1 where id="
    + ring.getId();
    sellRecordDao.deleteDt(sql);
    }
    }
    if (i == rings.size() - 1) {
    disconnect(); // 断开ftp连接
    // 修改上传状态
    ConfigFilePath.updateConfigByParaName("soundsUploadTag","0");
    }
    }
    }
    }
    } /**
     * 连接FTP服务器
     * 
     * @param serverIP
     * @param user
     * @param password
     * @return boolean
     */ public boolean connectFtpServer(String serverIP, String user,
    String password, int port) {
    ftp = new FTPClient();
    int reply;
    try {
    ftp.connect(serverIP, port);
    reply = ftp.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
    ftp.disconnect();
    System.out.println("FTP服务器连接失败");
    return false;
    } if (!ftp.login(user, password)) {
    disconnect();
    System.out.println("FTP服务器登录失败");
    return false;
    }
    } catch (IOException e) {
    // 修改上传状态
    ConfigFilePath.updateConfigByParaName("soundsUploadTag", "0");
    disconnect();
    System.out.println("FTP服务器连接异常");
    // System.out.println(e);
    return false;
    }
    return true;
    } /**
     * 创建文件夹
     * 
     * @param path
     * @return boolean
     */ public boolean createDirectory(String path) {
    try {
    String[] dirArray = path.split("/");
    for (int i = 0; i < dirArray.length; i++) {
    if (dirArray[i] != null)
    if (!ftp.changeWorkingDirectory(dirArray[i])) {
    ftp.makeDirectory(dirArray[i]);
    ftp.changeWorkingDirectory(dirArray[i]);
    }
    }
    } catch (IOException e) {
    // 修改上传状态
    ConfigFilePath.updateConfigByParaName("soundsUploadTag", "0");
    disconnect();
    System.out.println("路径创建进入失败!");
    // System.out.println(e);
    return false;
    }
    return true;
    } /**
     * 上传文件
     * 
     * @param local
     * @param remote
     * @return boolean
     */ public boolean uploadFile(String local, String remote, String sound, long id) {
    FileInputStream fis = null;
    try {
    File srcFile = new File(local);
    fis = new FileInputStream(srcFile);
    // 设置上传目录
    ftp.changeWorkingDirectory(remote);
    ftp.setBufferSize(1024);
    ftp.setControlEncoding("GBK");
    // 设置文件类型(二进制)
    ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
    ftp.storeFile(sound, fis);
    System.out.println(local + "文件上传到" + remote + "成功!");
    } catch (IOException e) {
    ConfigFilePath.updateConfigByParaName("soundsUploadTag", "0");

    String sql = "update ringoutput set flag=2 where id=" + id;
    sellRecordDao.deleteDt(sql);
    disconnect();
    System.out.println(local + "上传到" + remote + "失败!");
    // System.out.println(e);
    return false;
    }
    return true;
    } /**
     * 断开连接
     */ public void disconnect() {
    if (ftp.isConnected()) {
    try {
    ftp.logout();
    ftp.disconnect();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    } public ISellRecordDao getSellRecordDao() {
    return sellRecordDao;
    }
      

  2.   

    线程等待中,你用debug看看谁锁住了资源
      

  3.   

    java怎么用debug看呀??如果有ftp上传的方法也可以呀,只要能让我上传上去就可以
      

  4.   

    今天也遇到了这个问题,后来解决了
    http://blog.csdn.net/lgm277531070/archive/2010/09/08/5871175.aspx
    应该是客户端TCP的0端口被占用,或者防火墙的问题
    关了所有防火墙,重启机器就好了
      

  5.   

    你可以尝试在store之前调用c.enterRemotePassiveMode();可能是由于你的网关等无法转换PORT命令。使用Passive就可以
      

  6.   

    这问题...上传小的文件可以不?
    这怎么像我以前遇到的那个用hibernate来存储大的二进制数据到数据库的问题、也是莫名的停到那个地方,不报错,但就是存不到里面去