简体   繁体   中英

apache commons ftp client file upload issue

I have few excel files locally on my machine. I want to upload this excel file to ftp. I m using apache commons FTPClinet. But when it uploads the file, it is corrupted and size of the is zero. Here is the sample program

Can anyone point me where am i doing wrong?

public class App {
    private static final String server = "localhost";
    private static final String username = "test";
    private static final String password = "test";
    private static final String directory = "/home/files";

    public static void main(String[] args) throws SocketException, IOException {
        FTPClient f = new FTPClient();
        f.connect(server);
        f.login(username, password);
        f.setFileType(FTPClient.BINARY_FILE_TYPE);
        InputStream is = null;

        is = new FileInputStream("c:\\tmp\\output.xls");
        Boolean isStored = f.storeFile("status.xls", is);
        is.close();
    }
}

Don't use the f.setFileType(FTPClient.BINARY_FILE_TYPE); Remove that line.

Excel files are not binary, they should be transferred as ascii, which is the default for apache commons FTPClient I think.

I have't tested this. Give it a try.

Also change is from InputStream to FileInputStream

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM