FTPClient's setFileTransferMode Not Taking Effect

时光毁灭记忆、已成空白 提交于 2019-12-02 01:05:11

问题


The following code is meant to take a file (any file would be nice, but right now I'm just using images anyway), and upload it to my server (which works, blah blah blah). The only problem is that the picture is quite skewed after transfer. The main suggestion is to use FTPClient's setFileTranferMode to FTPClient.BINARY_FILE_TYPE, which... has no effect at this point...

Here's the code for the method:

public void sendFile(File sendMe) throws IOException{
    f.connect(ip);
    f.login(username, password);

    String recipient=null;
    while(!f.changeWorkingDirectory(path+recipient)){
        recipient=JOptionPane.showInputDialog("What is the name of the computer you are sending this to?");
    }

    f.changeWorkingDirectory(path+recipient);
    f.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
    f.storeFile(sendMe.getName(), new BufferedInputStream(new FileInputStream(sendMe)));
    System.out.println("Stored!");

    f.disconnect();
    System.out.println("Uploaded");
}

As always, any help would be much appreciated! Thanks!


回答1:


You are not using the correct method to set the file type. You should use setFileType instead.

f.setFileType(FTPClient.BINARY_FILE_TYPE);



回答2:


Instead of relying on 3rd party FTP clients, why don't you build your own in VB.NET or C#. This way you will have more control if something goes wrong. Here is the code to to just that:

http://dot-net-talk.blogspot.com/2008/12/how-to-create-ftp-client-in-vbnet.html



来源:https://stackoverflow.com/questions/9218245/ftpclients-setfiletransfermode-not-taking-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!