我是android新手,我使用下面的代码从FTP下载XML文件。它在Java中工作正常。但是在Android中它无法连接到FTP它给出以下异常。如何在android下载xml文件?
java.io.IOException: Unable to connect to server: Unable to retrieve file: 550
我已经在清单文件中包含了Internet权限标签。我怎样才能
XML File(manifest file)
<uses-permission android:name="android.permission.INTERNET" />
Java Files
protected void testFTP() throws Exception {
final String localfile = "/data/data/com.itwine/files/index.xml";
final String targetfile = "index.xml";
final String host = "ftp.qualityinaction.net/QIA/Questions/Airlines";
final String user = "qualityinaction.net";
final String password = "password";
try
{
URL url = new URL("ftp://"+ user+ ":"+ password+ "@"+ host + "/"+
targetfile+ ";type=i");
URLConnection urlc = url.openConnection();
urlc.setDoOutput(true);
// the following line throws "unable to connect to host {0}"
OutputStream os = urlc.getOutputStream();
FileInputStream is= new FileInputStream(localfile);
byte[] buf= new byte[16384];
int c;
while (true) {
c= is.read(buf);
if (c<= 0) break;
os.write(buf, 0, c);
}
os.close();
is.close();
urlc = null; // close
}
catch(Exception e)
{
Log.e("Exception", e.toString());
}
}
Exception list*
java.io.IOException异常:无法连接到服务器:无法检索文件:550
的只是想指出你离开你的密码很难在你的问题编码。如果那是敏感的信息,那么这是可信的。 – Graeme
我认为5 **是服务器端错误。 –
但通过浏览器我可以访问服务器,这个代码在Android中的作品? –