Java FTP文件说它已上载但未出现在服务器上

时间:2016-02-25 06:39:34

标签: java file upload ftp

我试图创建一个文件并将其写入程序到FTP文件服务器。 .getReply()方法提供了

  

" 226-文件已成功转移。"

尽管如此,该文件大约95%的时间都没有显示在服务器上。它偶尔会起作用,但很少。我无法确定何时上传的具体趋势。

try{
    String userName = "";

    FTPClient client = new FTPClient();
    client.connect("host", 21);
    boolean login = client.login("username", "password");
    client.enterLocalPassiveMode();
    client.setFileType(FTP.BINARY_FILE_TYPE);

    String remoteFile = "/scores/";  
    BufferedReader read = new BufferedReader(new FileReader(file));
    userName = read.readLine();
    File localStore = new File(dir + "\\results\\" + userName + ".txt");
    localStore.getParentFile();
    localStore.createNewFile();
    FileWriter write = new FileWriter(localStore);
    String br = "BREAK";
    write.write(cpuName);
    write.write(br);
    write.write(CPUs);
    write.write(br);
    write.write(gpuName + " x" + gpuAmt);
    write.write(br);
    write.write(mbInfo);
    write.write(br);
    write.write(os);
    write.write(br);
    write.write(finalScore);
    write.close();
    if (login){
        String userdetail = "/scores/" + userName + ".txt";
        System.out.println(userName);
        InputStream input = new FileInputStream(localStore);
        boolean a = client.storeFile(userdetail, input);
        this.sleep(5000);
        System.out.println(client.getReplyString());
        input.close();
        client.logout();    
        client.disconnect();
    }
}catch (Exception err){}

我非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

在你的捕获中,你什么都不是。至少添加代码以记录抛出异常时会发生什么。

可能有例外,但你不知道。