将Android APP连接到FTP服务器

时间:2013-05-30 12:13:40

标签: java android ftp filezilla

我在将android应用程序连接到filezilla ftp服务器时遇到问题。服务器正常运行,但我仍然在LogCat上获得此输出:

05-30 19:49:43.872: D/$$$$$$$$$$$$$$$$$$(1693): $$$$$$$$$$$$$$$$$$$$$$$$$ ERROR 1
05-30 19:50:04.913: W/System.err(1693): java.net.SocketTimeoutException: Connection timed out
05-30 19:50:04.913: W/System.err(1693): at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
05-30 19:50:04.913: W/System.err(1693): at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357)
05-30 19:50:04.913: W/System.err(1693): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:204)
05-30 19:50:04.913: W/System.err(1693): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
05-30 19:50:04.913: W/System.err(1693): at java.net.Socket.connect(Socket.java:1002)
05-30 19:50:04.913: W/System.err(1693): at org.apache.commons.net.SocketClient.connect(SocketClient.java:175)
05-30 19:50:04.913: W/System.err(1693): at org.apache.commons.net.SocketClient.connect(SocketClient.java:196)
05-30 19:50:04.913: W/System.err(1693): at org.apache.commons.net.SocketClient.connect(SocketClient.java:289)
05-30 19:50:04.913: W/System.err(1693): at General.FTPHandle.Connect(FTPHandle.java:40)
05-30 19:50:04.913: W/System.err(1693): at General.FTPHandle.doInBackground(FTPHandle.java:30)
05-30 19:50:04.913: W/System.err(1693): at General.FTPHandle.doInBackground(FTPHandle.java:1)
05-30 19:50:04.913: W/System.err(1693): at android.os.AsyncTask$2.call(AsyncTask.java:185)
05-30 19:50:04.913: W/System.err(1693): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
05-30 19:50:04.913: W/System.err(1693): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
05-30 19:50:04.913: W/System.err(1693): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
05-30 19:50:04.933: W/System.err(1693): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
05-30 19:50:04.933: W/System.err(1693): at java.lang.Thread.run(Thread.java:1019)

代码如下:

public class FTPHandle extends AsyncTask<String, String, String>
{
    public FTPClient client = null;
    public FileInputStream fis = null;
    private File root;
    private File dir;

    public FTPHandle()
    {
        client = new FTPClient();
        fis = null; 
        root = android.os.Environment.getExternalStorageDirectory();
        dir = new File (root.getAbsolutePath()+ "/TrackingData"); //creates directory
        execute();
    }

    protected String doInBackground(String... arg0) {
        Connect();
        return null;
    }

    public int Connect()
    {
        int status = 0;

        try {
            Log.d("$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$$ ERROR 1");
            client.connect("192.168.1.64");
            Log.d("$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$$ ERROR 2");

            // Create an InputStream of the file to be uploaded
            fis = new FileInputStream(dir);
            // Store file to server
            client.storeFile(dir.getName(), fis);
            client.logout();

            status = 1;
        } catch (IOException e) {
            e.printStackTrace();

            status = 0;
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                }
                client.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return status;
    }
}

Ps:服务器正常运行。我已经测试了它;)

亲切的问候

0 个答案:

没有答案