connect适用于Hardcoded String, 如果我从EditText获取字符串,我将获得异常 喜欢没有主持人的路线 我在一个线程中运行以下代码
FTPClient ftpclient = null;
boolean status = false;
final String ipaddress = edittext.gettext.tostring();
try {
ftpclient = new FTPClient();
ftpclient.connect(ipaddress,21); //工作完美 ftpclient.connect(,21); //不起作用 //但两个字符串都有相同的值。
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();
}
06-25 17:50:43.763 11106-11419 / com.example.ftptest W / System.err:java.net.ConnectException:无法连接到/94.74.194.126(端口21):连接失败:ECONNREFUSED(拒绝连接) 06-25 17:50:43.763 11106-11419 / com.example.ftptest W / System.err:at libcore.io.IoBridge.connect(IoBridge.java:114)