connect works fine for Hardcoded String, if i get the string from EditText i am getting exception like no route to host I am Running the below code in a thread
FTPClient ftpclient = null;
boolean status = false;
final String ipaddress = edittext.gettext.tostring();
try {
ftpclient = new FTPClient();
ftpclient.connect(ipaddress, 21); //works perfect ftpclient.connect(,21);//doesn't work //but both strings have same value.
if (FTPReply.isPositiveCompletion(ftpclient.getReplyCode())) {
if (ftpclient.login(usrname, passwd)) {
ftpclient.enterLocalPassiveMode();
ftpclient.setFileType(FTP.BINARY_FILE_TYPE);
String data = getFilePath(filesize);
FileInputStream in = new FileInputStream(new File(data));
String filestr = deviceId + Long.toString((new File(data)).length()) + "Bytes.txt";
Log.d("BLTtest", " filename: " + filestr);
boolean result = ftpclient.storeFile(filestr, in);
in.close();
if (result) {
status = true;
Log.v("upload result", "succeeded");
} else Log.v("upload result", "failed to upload");
//ftpclient.deleteFile(filestr);
ftpclient.logout();
ftpclient.disconnect();
}
}
} catch (Exception e) {
e.printStackTrace();
return status;
} finally {
ftpclient.disconnect();
}
Logcat:
06-25 17:50:43.763 11106-11419/com.example.ftptest W/System.err﹕ java.net.ConnectException: failed to connect to /94.74.194.126 (port 21): connect failed: ECONNREFUSED (Connection refused) 06-25 17:50:43.763 11106-11419/com.example.ftptest W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:114)