How to copy a file in FTP server using FTPClient in Java?

怎甘沉沦 提交于 2019-11-28 13:07:17
Martin Prikryl

I believe your code cannot work. You cannot download and upload a file over a single FTP connection at the same time.

You have two options:

  • Download the file completely first (to a temporary file or to a memory).

    The accepted answer to How to copy a file on the ftp server to a directory on the same server in java? shows the "to memory" solution. Note the outputStream.toByteArray() call.

  • Open two connections (two instances of the FTPClient) and copy the file between the instances.

    InputStream inputStream = ftpClient1.retrieveFileStream(cvs_name + ".csv");
    ftpClient2.storeFile(cvs_name2 + ".csv", inputStream);
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!