Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
7.7k views
in Java FTP by (320 points)
Hi ,
i am glad to have such a kind of library for ftp client. I am currently making an android application.
But on the first step i faced a little problem. The problem is of host not resolved. i want to access the ftp . should i have to provide any other link than www.mysite.com ?



(i) java.net.UnknownHostException: Unable to resolve host "http://www.myweb.com/": No address associated with hostname

here is my main activity android apps code..

public class MainActivity extends Activity implements OnClickListener{

FileTransferClient ftp = null;
Button cOnnect;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ftp = new FileTransferClient();
cOnnect = (Button) findViewById(R.id.button1);
cOnnect.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button1:
new myAsynTask().execute();
break;


}

}

public class myAsynTask extends AsyncTask<String, String, String>{
ProgressDialog pDialog;
@Override
protected void onPreExecute() {
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}



@Override

protected String doInBackground(String... params) {
try {
ftp.setRemoteHost("http://www.myweb.com/");
ftp.setUserName("myUserName");
ftp.setPassword("myPass");
ftp.getAdvancedSettings().setAutoLogin(false);
ftp.connect();
ftp.manualLogin();
} catch (FTPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;



}

@Override

protected void onPostExecute(String result) {
// TODO Auto-generated method stub

pDialog.dismiss();
}
}




===========
Here is stack log cat.

09-19 18:01:28.118: W/System.err(782): java.net.UnknownHostException: Unable to resolve host "http://www.myweb.com/": No address associated with hostname
09-19 18:01:28.296: W/System.err(782): at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
09-19 18:01:28.316: W/System.err(782): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
09-19 18:01:28.316: W/System.err(782): at java.net.InetAddress.getByName(InetAddress.java:289)
09-19 18:01:28.316: W/System.err(782): at com.enterprisedt.net.ftp.FTPClient.connect(FTPClient.java:999)
09-19 18:01:28.316: W/System.err(782): at com.enterprisedt.net.ftp.FileTransferClient.connect(FileTransferClient.java:392)
09-19 18:01:28.316: W/System.err(782): at com.example.secondftp.MainActivity$myAsynTask.doInBackground(MainActivity.java:72)
09-19 18:01:28.316: W/System.err(782): at com.example.secondftp.MainActivity$myAsynTask.doInBackground(MainActivity.java:1)
09-19 18:01:28.316: W/System.err(782): at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-19 18:01:28.326: W/System.err(782): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-19 18:01:28.356: W/System.err(782): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-19 18:01:28.416: W/System.err(782): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-19 18:01:28.416: W/System.err(782): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
09-19 18:01:28.416: W/System.err(782): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
09-19 18:01:28.486: W/System.err(782): at java.lang.Thread.run(Thread.java:856)
09-19 18:01:28.506: W/System.err(782): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
09-19 18:01:28.517: W/System.err(782): at libcore.io.Posix.getaddrinfo(Native Method)
09-19 18:01:28.536: W/System.err(782): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
09-19 18:01:28.606: W/System.err(782): at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
09-19 18:01:28.646: W/System.err(782): ... 13 more


==============
Kindly help me in solving the problem... or either provide me any complete application with complete code for ftp client. I shall be thank full to you.

take care. waiting for your reply.
Thanks.

9 Answers

0 votes
by (162k points)
http://www.myweb.com is not a valid hostname. You need to use www.myweb.com
0 votes
by (320 points)
I have used www.mysite.com ...
but i am still getting the same error..
i have also tried ftp.mysite.com
still the same error... any other solution.
0 votes
by (162k points)
Can you use some other tool to work out what the valid hostname is? Apparently your phone can't resolve it. Can you reach the site on your phone's browser?
0 votes
by (320 points)
Thanks mate i have connected to it...
now i am trying to get the complete directory from my /public_html/
Is there any post which can help me ...
i am learning and trying the whole process from your provided documentation ...
at current time i am using string[] files = ftp.directoryNameList();

and getting errors.
Thanks alot for your help.. need little more help on it.
0 votes
by (320 points)
I am now trying to show my public_html directory's all folders and files into a listview in my android application. I have tried both

string[] files = ftp.directoryNameList();
and
string[] description = ftp.directoryNameList("public_html",true);

but getting errors.. here is my code for displaying the public_html directory into list view in android.


public class SecondActivity extends ListActivity {

FileTransferClient ftp = null;
String[] files;
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);



new getDirectoriesAsync().execute();



}
public class getDirectoriesAsync extends AsyncTask<String, String, String>{
ProgressDialog pDialog;
@Override
protected void onPreExecute() {
pDialog = new ProgressDialog(SecondActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();

}



@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub



try {
files = ftp.directoryNameList();
/ files = ftp.directoryNameList("public_html",true);
System.out.println(files);
Log.e(files.toString(), "Printing Files"+ files.toString());

} catch (FTPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block

e.printStackTrace();
}

setListAdapter(new ArrayAdapter<String>(SecondActivity.this, android.R.layout.simple_list_item_1, files));

ArrayAdapter<String> adp = new ArrayAdapter<String>(SecondActivity.this, android.R.layout.select_dialog_singlechoice,files);


return null;
}

@Override
protected void onPostExecute(String result) {

pDialog.dismiss();
}


}
}
========================================
The error list is

09-20 15:21:13.345: W/System.err(1421): com.enterprisedt.net.ftp.FTPException: 500 I won't open a connection to 10.0.2.2 (only to 221.120.210.138)
09-20 15:21:13.395: W/System.err(1421): at com.enterprisedt.net.ftp.FTPControlSocket.validateReply(FTPControlSocket.java:1223)
09-20 15:21:13.395: W/System.err(1421): at com.enterprisedt.net.ftp.FTPControlSocket.setDataPort(FTPControlSocket.java:815)
09-20 15:21:13.395: W/System.err(1421): at com.enterprisedt.net.ftp.FTPControlSocket.sendPORTCommand(FTPControlSocket.java:669)
09-20 15:21:13.395: W/System.err(1421): at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocketActive(FTPControlSocket.java:616)
09-20 15:21:13.395: W/System.err(1421): at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocket(FTPControlSocket.java:583)
09-20 15:21:13.395: W/System.err(1421): at com.enterprisedt.net.ftp.FTPClient.setupDataSocket(FTPClient.java:2648)
09-20 15:21:13.405: W/System.err(1421): at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3664)
09-20 15:21:13.405: W/System.err(1421): at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3756)
09-20 15:21:13.405: W/System.err(1421): at com.enterprisedt.net.ftp.FTPClient.dirDetails(FTPClient.java:3583)
09-20 15:21:13.405: W/System.err(1421): at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:647)
09-20 15:21:13.455: W/System.err(1421): at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:633)
09-20 15:21:13.495: W/System.err(1421): at com.example.secondftp.MainActivity$getDirectory.doInBackground(MainActivity.java:144)
09-20 15:21:13.495: W/System.err(1421): at com.example.secondftp.MainActivity$getDirectory.doInBackground(MainActivity.java:1)
09-20 15:21:13.535: W/System.err(1421): at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-20 15:21:13.595: W/System.err(1421): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-20 15:21:13.685: W/System.err(1421): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-20 15:21:13.685: W/System.err(1421): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-20 15:21:13.685: W/System.err(1421): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
09-20 15:21:13.685: W/System.err(1421): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
09-20 15:21:13.685: W/System.err(1421): at java.lang.Thread.run(Thread.java:856)

=======================================

Kindly tell me how can i get the directories on my list view from public_html.

Thanks alot...
0 votes
by (162k points)
You need to set the active IP address here - the server is trying to open a connection to your client and it needs a public IP address to do so. Perhaps the one suggested in the error message is the one required.

ftp.getAdvancedFTPSettings().setActiveIPAddress("221.120.210.138");
0 votes
by (320 points)
Here is the changed code..

Sorry i forget to post the code... here it z.

FileTransferClient ftp = null;
static String[] files;
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

new getDirectoriesAsync().execute();



}
public class getDirectoriesAsync extends AsyncTask<String, String, String>{
ProgressDialog pDialog;
@Override
protected void onPreExecute() {
pDialog = new ProgressDialog(SecondActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();

}



@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub


try {
ftp.getAdvancedFTPSettings().setActiveIPAddress("221.120.210.138");
//files = ftp.directoryNameList("/public_html",true);


} catch (FTPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

setListAdapter(new ArrayAdapter<String>(SecondActivity.this, android.R.layout.simple_list_item_1, files));

ArrayAdapter<String> adp = new ArrayAdapter<String>(SecondActivity.this, android.R.layout.select_dialog_singlechoice,files);


return null;
}

@Override
protected void onPostExecute(String result) {

pDialog.dismiss();
}


}
}
=================================================================
Error logs.

09-20 18:33:13.594: E/AndroidRuntime(2077): FATAL EXCEPTION: AsyncTask #2
09-20 18:33:13.594: E/AndroidRuntime(2077): java.lang.RuntimeException: An error occured while executing doInBackground()
09-20 18:33:13.594: E/AndroidRuntime(2077): at android.os.AsyncTask$3.done(AsyncTask.java:299)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-20 18:33:13.594: E/AndroidRuntime(2077): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.lang.Thread.run(Thread.java:856)
09-20 18:33:13.594: E/AndroidRuntime(2077): Caused by: java.lang.NullPointerException
09-20 18:33:13.594: E/AndroidRuntime(2077): at com.example.secondftp.SecondActivity$getDirectoriesAsync.doInBackground(SecondActivity.java:49)
09-20 18:33:13.594: E/AndroidRuntime(2077): at com.example.secondftp.SecondActivity$getDirectoriesAsync.doInBackground(SecondActivity.java:1)
09-20 18:33:13.594: E/AndroidRuntime(2077): at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-20 18:33:13.594: E/AndroidRuntime(2077): ... 5 more
0 votes
by (162k points)
That looks like a NPE in your code to me.
0 votes
by (320 points)
Here is the changed code..

Sorry i forget to post the code... here it z.

FileTransferClient ftp = null;
static String[] files;
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

new getDirectoriesAsync().execute();



}
public class getDirectoriesAsync extends AsyncTask<String, String, String>{
ProgressDialog pDialog;
@Override
protected void onPreExecute() {
pDialog = new ProgressDialog(SecondActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();

}



@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub


try {
ftp.getAdvancedFTPSettings().setActiveIPAddress("221.120.210.138");
//files = ftp.directoryNameList("/public_html",true);


} catch (FTPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

setListAdapter(new ArrayAdapter<String>(SecondActivity.this, android.R.layout.simple_list_item_1, files));

ArrayAdapter<String> adp = new ArrayAdapter<String>(SecondActivity.this, android.R.layout.select_dialog_singlechoice,files);


return null;
}

@Override
protected void onPostExecute(String result) {

pDialog.dismiss();
}


}
}
=================================================================
Error logs.

09-20 18:33:13.594: E/AndroidRuntime(2077): FATAL EXCEPTION: AsyncTask #2
09-20 18:33:13.594: E/AndroidRuntime(2077): java.lang.RuntimeException: An error occured while executing doInBackground()
09-20 18:33:13.594: E/AndroidRuntime(2077): at android.os.AsyncTask$3.done(AsyncTask.java:299)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-20 18:33:13.594: E/AndroidRuntime(2077): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.lang.Thread.run(Thread.java:856)
09-20 18:33:13.594: E/AndroidRuntime(2077): Caused by: java.lang.NullPointerException
09-20 18:33:13.594: E/AndroidRuntime(2077): at com.example.secondftp.SecondActivity$getDirectoriesAsync.doInBackground(SecondActivity.java:49)
09-20 18:33:13.594: E/AndroidRuntime(2077): at com.example.secondftp.SecondActivity$getDirectoriesAsync.doInBackground(SecondActivity.java:1)
09-20 18:33:13.594: E/AndroidRuntime(2077): at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-20 18:33:13.594: E/AndroidRuntime(2077): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-20 18:33:13.594: E/AndroidRuntime(2077): ... 5 more

Categories

...