1

I have upload to image from device Sd card to FTP server using android studio.when i upload the image,image successfully uploaded on first time and 2nd time uploaded the another image the "new AsyncTask()" not call what i do some one help me what is my mistake where i change the code.. my code is.

UploadFTP() Method

 public void UploadFTP() {
        new AsyncTask<Void, Void, String>() {
            String Z = "";
            String y = "";

            @Override
            protected String doInBackground(Void... params) {
                Looper.prepare();
                // return null;
                FTPClient client = new FTPClient();

                try {

                    client.connect(FTP_HOST, 21);// here i get error: java.
                    client.login(FTP_USER, FTP_PASS);
                    client.setType(FTPClient.TYPE_BINARY);
                    client.setPassive(true);
                    client.noop();
                    client.changeDirectory("/FBApp_Images/");

                    client.upload(f, new MyTransferListener());
                    Z = "Success";

                } catch (Exception e) {
                    e.printStackTrace();
                    try {
                        client.disconnect(true);
                    } catch (Exception e2) {
                        e2.printStackTrace();
                        Z = e2.toString();
                    }
                    Z = e.toString();
                }
                Looper.loop();
                return null;
            }

            @Override
            protected void onPostExecute(String s) {
               // txtmsg.setText("Success");
                Toast.makeText(Admin.this,s,Toast.LENGTH_SHORT).show();
                super.onPostExecute(s);
            }

        }.execute();

    }
Anbu
  • 57
  • 5

0 Answers0