我的应用程序正在将文件从SD卡上载到FileZilla FTP服务器上的目录。运行appliaction之后,它给了我一个异常,经过如此多的搜索,我无法解决这个异常。
以下是日志CAT输出:

06-24 11:06:53.715: W/System.err(1304): java.io.IOException: SimpleFTP received an unknown response when connecting to the FTP server: 220-FileZilla Server version 0.9.41 beta
06-24 11:06:54.055: W/System.err(1304):     at org.jibble.simpleftp.SimpleFTP.connect(SimpleFTP.java:74)
06-24 11:06:54.087: W/System.err(1304):     at com.example.upload1.MainActivity$UploadVideo.doInBackground(MainActivity.java:63)
06-24 11:06:54.167: W/System.err(1304):     at com.example.upload1.MainActivity$UploadVideo.doInBackground(MainActivity.java:1)
06-24 11:06:54.167: W/System.err(1304):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-24 11:06:54.167: W/System.err(1304):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-24 11:06:54.167: W/System.err(1304):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-24 11:06:54.167: W/System.err(1304):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-24 11:06:54.167: W/System.err(1304):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-24 11:06:54.403: W/System.err(1304):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-24 11:06:54.403: W/System.err(1304):     at java.lang.Thread.run(Thread.java:856)

这是我的mainactivity.java代码
import java.io.File;

    import org.jibble.simpleftp.SimpleFTP;

    import android.app.Activity;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.os.Environment;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Toast;
    //import com.kpbird.ftpdemo.R;




    public class MainActivity extends Activity implements OnClickListener {
        //FTPClient client;


    /*********  work only for Dedicated IP ***********/
    static final String FTP_HOST= "203.199.134.131";

    /*********  FTP USERNAME ***********/
    static final String FTP_USER = "a_gupta";

    /*********  FTP PASSWORD ***********/
    static final String FTP_PASS  ="AditI123";

    Button btn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn = (Button) findViewById(R.id.button1);
        btn.setOnClickListener(this);
    }
    public void onClick(View v) {
        UploadFile async = new UploadFile();
        async.execute();

        }

        class UploadFile extends AsyncTask<String, Integer, String> {

        @Override
        protected String doInBackground(String... params) {
        // ftpClient=uploadingFilestoFtp();
        try {
        SimpleFTP ftp = new SimpleFTP();

        ftp.connect(FTP_HOST, 21, FTP_USER, FTP_PASS);

        ftp.bin();

        // Change to a new working directory on the FTP server.
        ftp.cwd("callrecording");

        // Upload some files.
        ftp.stor(new File(Environment.getExternalStorageDirectory().getParent() + "/invite_json.txt"));
        // ftp.stor(new File("comicbot-latest.png"));

        // You can also upload from an InputStream, e.g.
        // ftp.stor(new FileInputStream(new File("test.png")),
        // "test.png");
        // ftp.stor(someSocket.getInputStream(), "blah.dat");

        // Quit from the FTP server.
        ftp.disconnect();

        } catch (Exception e) {
        e.printStackTrace();
        }

        return null;
        }

        @Override
        protected void onPreExecute() {
        super.onPreExecute();
        // dialog.show();
        }

        @Override
        protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        Toast.makeText(MainActivity.this, "sent", Toast.LENGTH_LONG).show();
        }
        }

最佳答案

过了这么多天,我又做了这件事,成功地把事情办好了。所以,我要把我的答案贴出来。希望它能帮助一些人。
这是我的主要活动代码:

package com.example.ftpup;

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

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {


    /*********  work only for Dedicated IP ***********/
    static final String FTP_HOST= "203.199.134.131";

    /*********  FTP USERNAME ***********/
    static final String FTP_USER = "a_gupta";

    /*********  FTP PASSWORD ***********/
    static final String FTP_PASS  ="AditI123";
    public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
    Button btn;
    FTPClient client = new FTPClient();
    private ProgressDialog mProgressDialog;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn = (Button) findViewById(R.id.uploadButton);
        btn.setOnClickListener(this);

    }

    public void onClick(View v) {


         startDownload();
    }
   // /*******  Used to file upload and show progress  **********/




        private void startDownload() {
            //Pick file
            //File f = new File("/sdcard/invite_json.txt");
           // Async task

            new DownloadFileAsync().execute();
        }
        @Override
        protected Dialog onCreateDialog(int id) {
            switch (id) {
            case DIALOG_DOWNLOAD_PROGRESS:
                mProgressDialog = new ProgressDialog(this);
                mProgressDialog.setMessage("Downloading file..");
                mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                mProgressDialog.setCancelable(false);
                mProgressDialog.show();
                return mProgressDialog;
            default:
                return null;
            }
        }
        // Upload sdcard file


    //public void uploadFile(File fileName){

    class DownloadFileAsync extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            showDialog(DIALOG_DOWNLOAD_PROGRESS);


        }@Override
        protected String doInBackground(String... filename) {
            String sdcard = Environment.getExternalStorageDirectory().toString();
            File file = new File(sdcard+"/androrec/");
            //File file2 = new File("/mnt/sdcard/CallRecorderBackup");

            File[] listofFiles = file.listFiles();
            Log.d("No. of files" ,fileArrayToString(listofFiles));
            try{
                client.connect(FTP_HOST,21);



            for (int i = 0; i <=listofFiles.length ; i++) {


                    Log.d("Tag 4", "inside of ftp connect");

                Log.d("Tag 1", "inside of for loop");

                if (listofFiles == null || listofFiles[i].isFile()) {
                    Log.d("Tag 2", "inside of if");
                    String files = listofFiles[i].getName();
                    Log.d("Tag 3", "inside of files");

                    File filetoload = new File(sdcard+"/androrec/"+files);
                    String uploadingFiles = filetoload.toString();
                    Log.d("Files uploading to the server", uploadingFiles);
                    client.login(FTP_USER, FTP_PASS);
                            //client.connect(FTP_HOST,21);
                            Log.d("Tag 4", "inside of ftp connect");

                        Log.d("Tag 5", "inside of for ftp pass");
                        //client.setType(FTPClient.TYPE_BINARY);
                        //client.changeDirectory("/");
                        Log.d("Tag 6", "inside of for dir");

                    client.upload(filetoload);
                    Log.d("Tag 7", "inside of download");
                    //out.write(buf, 0, len);
                //}
                //}






           // client.upload(in, new MyTransferListener());

        }
                else{

                }
                //client.disconnect(true);
                }
            }

                 catch (IllegalStateException | IOException
                        | FTPIllegalReplyException | FTPException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (FTPDataTransferException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (FTPAbortedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


            try {
                client.disconnect(true);
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            return null;
            }



            /*}
            }*/

        @Override
        protected void onPostExecute(String unused) {
            dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
        }

    }

   // }
    String fileArrayToString(File[] f){
        String output = "";
        String delimiter = "\n" ;// Can be new line \n tab \t etc...
        for (int i=0; i<f.length; i++)
        {
            output = output + f[i].getPath() + delimiter;
        }

        return output;
    }

}

请在应用程序运行时检查日志猫,您将了解它是如何工作的。
谢谢。

08-27 11:41