在线程中使用ftpclient

时间:2013-06-29 06:10:27

标签: java android multithreading android-asynctask

我想在我的应用程序中使用ftp并在我的ftp服务器上创建一个目录这是我的代码我从我的Asynctask调用此类。

请回答我不知道该怎么做,请指出我的错误。

package dolphin.developers.com;


import java.net.InetAddress;

import org.apache.commons.net.ftp.FTPClient;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.widget.EditText;
import android.widget.Toast;
import dolphin.devlopers.com.R;


public class FTPCLIENT extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    Toast toast = Toast.makeText(getApplicationContext(), "Please Wait!!!", Toast.LENGTH_LONG);

    toast.show();

    EditText text =(EditText) findViewById(R.id.editText1);
    final String  str = text.getText().toString();


    final String server = "www.dolphin123.net78.net";
    final String user; 
    final String pass;  

    new Thread(new Runnable() {
        public void run() {
            Looper.prepare();
            FTPClient client = new FTPClient();
             try {
                    client.connect(InetAddress.getByName(server));
                    client.enterLocalPassiveMode();
                    client.login(user, pass);
                    client.changeWorkingDirectory("public_html");
                    client.makeDirectory(str);
                    client.logout();
                    client.disconnect(); 
            } 


             catch (Exception e) {


                 Context context = getApplicationContext();
                 CharSequence text = "Creating folder!!";
                 int duration = Toast.LENGTH_SHORT;

                 Toast toast = Toast.makeText(context, text, duration);
                 toast.show();
            }
        }
      }).start();

    }
    }

0 个答案:

没有答案