FTP文件已成功传输但不是真的

时间:2015-11-14 18:07:42

标签: java ftp

这是我的简单代码:

public boolean sendCSV() throws IOException {

    System.out.println("Translating from xls to csv...");
    File xls = new File("file.xls");
    File csvFile;
    csvFile = CSVManager.xlsToCsv(xls);
    csvFile.renameTo(new File("file.csv"));

    FTPClient client = new FTPClient();
    FileInputStream fis = null;

    try {
        System.out.println("Establishing connection...");
        client.connect(ftpHost, ftpPort);
        System.out.print(client.getReplyString());
        System.out.println("Connection ok.");
        if (client.login(ftpUser, ftpPass)) {
            System.out.println("Login ok");
            System.out.print(client.getReplyString());
            System.out.println("Setting PASV");
            client.enterLocalPassiveMode();
            System.out.print(client.getReplyString());

            if (client.changeWorkingDirectory("/MYDIR")) {
                System.out.println("Dir changed");
                System.out.print(client.getReplyString());
            } else {
                System.out.println("Error changing dir");
                System.out.print(client.getReplyString());
            }
            String filename = csvFile.getName();
            TrayIconManager.SwitchTrayToFull();
            fis = new FileInputStream(filename);
            if (client.storeFile(filename, fis)) {
                System.out.println("File sent");
                System.out.print(client.getReplyString());

            } else {
                System.out.println("Error during sending file");
                System.out.print(client.getReplyString());

            }
        }

        if (client.logout()) {
            System.out.println("Logout ok");
            System.out.print(client.getReplyString());
            return true;
        } else {
            System.out.println("Logout problem");
            System.out.print(client.getReplyString());
            return false;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
            client.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

有什么问题?输出说

  

发送的文件   使用226-29千字节(0%) - 授权:512000 Kb   226-文件成功传输   226 0.343秒(此处测量),每秒30.59千字节

但事实并非如此,因为一旦我检查了ftp服务器,该文件就不存在了! 为什么Kbytes使用的是0%?也许是错误? 代码似乎没问题,也是输出。 那真正的问题是什么?

0 个答案:

没有答案