FTP file corrupt after download with Apache Commons Net

前端 未结 3 1020
醉话见心
醉话见心 2021-01-14 16:42

The files downloaded by this, are nearly the same size but differ in some lines. Every answer points to binary file type. But this won\'t help. Got anybody an idea for the p

相关标签:
3条回答
  • 2021-01-14 17:19

    While my problem was related to corruption of the upload, I resolved similar issue by moving the set of file type after ftp login (I dont use transfer mode leaving it to its default value):

    resultOk &= ftpClient.login(usr, pwd);
    ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
    

    I saw in some forums that setting binary file type before invoking login method, could lead to problems in transfer. Before this change, PDF file get downloaded but show corrupted fonts and elements. Now it works. Hope it may helps someone.

    0 讨论(0)
  • 2021-01-14 17:19

    It seems to happen when using unescaped paths that contain spaces. E.g. C:/Documents and Settings/test

    Got it solved now by using a escaped path for the spaces. Thanks for your help

    0 讨论(0)
  • 2021-01-14 17:41

    It's clear from the files you have shared, that the transfer indeed happened in text/ascii mode.

    While probably not required by FTP specification, with some FTP servers (e.g. FileZilla server), you cannot change transfer type before logging in. But servers like IIS, ProFTPD or vsftpd have no problem with that. On the other hand FileZilla server defaults to binary mode anyway (what is another violation of the specification), so you are probably using yet another one.

    In any case, move the .setFileType call after .login. And test its return value.


    And remove the .setFileTransferMode call. It does not do any harm with most servers, as hardly any server support MODE C, hence the call is ignored anyway. But if you encounter a server that does, it would break the transfer, as FTPClient actually does not support it.

    0 讨论(0)
提交回复
热议问题