Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:01:50+00:00 2026-06-13T12:01:50+00:00

Hi I am trying to upload image to server using ftp4j. My image is

  • 0

Hi I am trying to upload image to server using ftp4j. My image is uploaded on server but getting corrupted. I know something is missing in my code.My code is

private class UploadBackgroundTask extends AsyncTask<String, Void, String> {

    protected void onPreExecute() {
        dialog = new ProgressDialog(xxx.this);
        dialog.setMessage("Loading");
        dialog.setCancelable(false);
        dialog.show();

    }

    protected String doInBackground(final String... args) {



        try{
            TrustManager[] trustManager = new TrustManager[] { new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
                public void checkClientTrusted(X509Certificate[] certs, String authType) {
                }
                public void checkServerTrusted(X509Certificate[] certs, String authType) {
                }
            } };

            SSLContext sslContext = null;
            try {
                sslContext = SSLContext.getInstance("TLS");
                sslContext.init(null, trustManager, new SecureRandom());
            } catch (Exception e) {
                e.printStackTrace();
            }
            SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
            FTPClient client = new FTPClient();

            client.setSSLSocketFactory(sslSocketFactory);
            client.setSecurity(FTPClient.SECURITY_FTPES);

            client.connect("xxx.xxx.com");
            client.login("xxx", "xxx");

            client.changeDirectory("product_images/import");
            client.setType(FTPClient.TYPE_BINARY);
            //@TODO read file from android system
            System.out.println("temPath -->"+picturepath);
            client.upload(new File(picturepath));


            FTPFile[] list = client.list();
            for(int i=0;i<list.length;i++){
                System.out.println("-->"+list[i]);
            }


            Log.v("SUCCESFULLY UPLOADED", "SUCCESFULLY UPLOADED");
            }catch(Exception ex){
                ex.printStackTrace();
            }


        return null;

    }

    protected void onPostExecute(String list) {
        dialog.dismiss();

    }
}

My image on server is:
enter image description here

My logTrace is:

it.sauronsoftware.ftp4j.FTPException [code=450, message= Transfer aborted. Link to file server lost]
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2799)
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2586)
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2495)
at com.Activity.xxx.AddProducts$UploadBackgroundTask.doInBackground(AddProducts.java:902)
at com.Activity.xxx.AddProducts$UploadBackgroundTask.doInBackground(AddProducts.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
 Window already focused, ignoring focus gain of:
com.android.internal.view.IInputMethodClient$Stub$Proxy@41174c80

File size is on server is always 4 KB after uploading.why?

I searched a lot but not getting answer.
Please tell me what is wrong in my code.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:01:55+00:00Added an answer on June 13, 2026 at 12:01 pm

    try to implement listener like this:

    import it.sauronsoftware.ftp4j.FTPDataTransferListener;
    
    public class MyTransferListener implements FTPDataTransferListener {
    
        public void started() {
            // Transfer started
        }
    
        public void transferred(int length) {
            // Yet other length bytes has been transferred since the last time this
            // method was called
        }
    
        public void completed() {
            // Transfer completed
        }
    
        public void aborted() {
            // Transfer aborted
        }
    
        public void failed() {
            // Transfer failed
        }
    
    }
    

    and upload file with client.upload(new File(picturepath), new MyTransferListener()); So you can track out what happens on file upload.

    EDIT:

    1. Check upladed image size and params in method transferred(int length) is equals. (in case image less than 64k)
    2. Check the same byte amount was received on FTP server ( check logs on FTP server)
    3. If one of conditions above is not true, problem in ftp4j, if both of them true, problem in your FTP server.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to upload an image to server using using XMLHttpRequest but fails.
i am trying to upload an image from a jsp page using servlet. but
I am trying to upload an image to server using iphone . I haven't
I'm trying to upload an image from android to a PHP server by using
I'm trying to upload an image using jQuery and PHP. I know there are
I am trying to upload an image file using ajax to the server. However,
I am trying to upload an image to the server. I hava a form
I have this Form I am trying to upload my image but every time
I am trying to upload an image of size 800kb using Ajax AsyncFileupload control
I am trying to upload image files to the server and it gives me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.