为null那里只给了文件名啊,服务端的路径呢?

解决方案 »

  1.   

    我现在怀疑是我的工作目录出问题了,登录到FTP上之后会跳转到指定目录。但这个目录是根目录,我现在传"/"、"//"、"\\"都不行。
    public void connectServer(String ip, int port, String userName,
    String userPwd, String path) {
    ftpClient = new FTPClient();
    try {
    // 连接
    ftpClient.connect(ip, port);
    // 登录
    ftpClient.login(userName, userPwd);
    if (path != null && path.length() > 0) {
    // 跳转到指定目录
    ftpClient.changeWorkingDirectory(path);
    }
    } catch (SocketException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
      

  2.   

    因为是FTP根目录,我只给了文件名。
      

  3.   

    以下代码就是问题代码。不知道为什么fclient.retrieveFileStream一直无法取出来
    try {
    FTPClient fclient = new FTPClient();
    fclient.connect("127.0.0.1", 21); fclient.login("root", "root");
    System.out.println(fclient.isConnected());
    fclient.changeWorkingDirectory(null);
    fclient.setBufferSize(1024);    
    fclient.setFileType(FTP.BINARY_FILE_TYPE); 
    FileOutputStream fileOutputStream = new FileOutputStream("c:\\a.txt");
    InputStream ins = null;
    ins = fclient.retrieveFileStream("20141201.txt");
    if (null != ins) {
    System.out.println("===========");
    byte[] b = new byte[ins.available()];
    while ((ins.read(b)) != -1) {
    fileOutputStream.write(b);
    }
    fileOutputStream.close();
    ins.close();
    fclient.getReply();
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
      

  4.   

    登录之后 先做一下list  看看结果
      

  5.   

    设置成被动模式就好了。但是现在问题很奇怪。测试debug模式的时候可以下载文件。但生产模式运行的时候就下载不了。http://bbs.csdn.net/topics/390944928?page=1#post-398618127