FTPClient corrupts the images while uploading to ftp server on android?

我的未来我决定 提交于 2019-11-28 12:17:57

Apache FTP Client has several outstanding issues with this. Below are instructions on how to use Ftp4J to effectively handle ftp programatically though java.

Download Ftp4J: http://www.sauronsoftware.it/projects/ftp4j/download.php

Then in your IDE:

import java.io.File;
import java.io.IOException;

import it.sauronsoftware.ftp4j.FTPAbortedException;
import it.sauronsoftware.ftp4j.FTPClient;
import it.sauronsoftware.ftp4j.FTPDataTransferException;
import it.sauronsoftware.ftp4j.FTPException;
import it.sauronsoftware.ftp4j.FTPIllegalReplyException;

public class FTP4J {

    /**
     * @param args
     * @throws FTPAbortedException 
     * @throws FTPDataTransferException 
     * @throws FTPException 
     * @throws FTPIllegalReplyException 
     * @throws IOException 
     * @throws IllegalStateException 
     */
    public static void main(String[] args) throws IllegalStateException, IOException, FTPIllegalReplyException, FTPException, FTPDataTransferException, FTPAbortedException {
        FTP4J ftp= new FTP4J();
        ftp.transfer();
    }

    private void transfer() throws IllegalStateException, IOException, FTPIllegalReplyException, FTPException, FTPDataTransferException, FTPAbortedException{
        FTPClient client = new FTPClient();
        client.connect("192.168.0.1"); //conect to FTP server (in my case a vsftp on centos 6.4)
        client.login("admn", "admn123");//login to FTP Server
        client.changeDirectory("/usr/share/tomcat/webapps/imgs/"); //tell FTP4J where on the Ftp Server to send your file that you want to upload.
        File fileUpload = new File ("C:\\Users\\ih8w8\\Pictures\\1.jpg"); //point FTP4J to the file you want to upload
        client.upload(fileUpload); //upload it
        client.disconnect(true); //close connection (note: you could also log out first, then disconn if youre not in a test env)
    }

}

Problem is solved. FTPClient class has "last packet data loss bug". But this was solved with 3.0.1 23.05.2011 release.

You can see from detailed explanation about bug: https://issues.apache.org/jira/browse/NET-409

You can download fixed relea https://repository.apache.org/content/repositories/snapshots/commons-net/commons-net/3.0.1-SNAPSHOT/

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