2011-07-12 68 views
0

我是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

+0

的只是想指出你离开你的密码很难在你的问题编码。如果那是敏感的信息,那么这是可信的。 – Graeme

+0

我认为5 **是服务器端错误。 –

+0

但通过浏览器我可以访问服务器,这个代码在Android中的作品? –

回答

0

编辑:

你现在提出可能无法与所有服务器工作的方法,它是在这里修改后的(也有采用额外的库解决方案):

Download from ftp

或我发现怎么做,与意图,但我没有测试任何这些解决方案

Download using intent

+0

谢谢对于响应,它会通过一个异常不是一个HTTP连接后,它不会执行HttpURLConnection httpConn =(HttpURLConnection)conn它会跳转到catch块如何解决这个请帮我 –

+0

显示你现在的代码和完整的堆栈跟踪例外情况会很好。 – porkshire

+0

完整的堆栈跟踪是(没有显式的返回值) –