2011-07-19 4 views
0

XMLファイルをftpからアンドロイドフォンメモリにダウンロードするために次のコードを使用しました。ftpに接続できるが、ローカルメモリにXMLを取得しているときに例外が発生します。07-19 15:01:03.721:DEBUG/SntpClient(61) :要求時に失敗しました:java.net.SocketExceptionが:アドレスファミリは誰か助けてくださいプロトコル でサポートされていないあなたに感謝し、次のアンドロイドコードを使用してftpからxmlファイルをダウンロードするには?

Javaクラス

private void fnfileDownloadBuf() 
{ 

    FTPClient client = new FTPClient(); 
FileOutputStream fos = null; 

try { 
    //client.connect("ftp://ftp.qualityinaction.net/QIA/Questions/Airlines/"); 
    client.connect("ftp.qualityinaction.net"); 
    client.login("qualityinaction.net","password"); 
    client.setFileType(FTP.BINARY_FILE_TYPE); 

    // 
    // The remote filename to be downloaded. 
    // 
    // String filename = "/QIA/Questions/Airlines/index.xml"; 
    String filename = getFilesDir().getAbsolutePath()+ File.separator + "/index.xml"; 
    // String filename = "/QIA/Questions/Airlines/index.xml"; 
    File file = new File(filename); 
    fos = new FileOutputStream(file); 

    // 
    // Download file from FTP server 
    // 
    //client.retrieveFile("/" + filename, fos); 
    client.retrieveFile("/QIA/Questions/Airlines/index.xml;type=i", fos); 
    // client.retrieveFile(getFilesDir().getAbsolutePath()+ File.separator + "/index.xml", fos); 
} catch (IOException e) { 
    e.printStackTrace(); 
} finally { 
    try { 
     if (fos != null) { 
      fos.close(); 
     } 
     client.disconnect(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

} 

マニフェストXMLファイル

<uses-permission android:name="android.permission.INTERNET"></uses-permission> 

例外

あなたはパッシブモードを使用する必要があり、そのための
exception 07-19 15:01:03.721: DEBUG/SntpClient(61): request time failed: java.net.SocketException: Address family not supported by protocol 
+0

コピーと、Googleの検索ボックスにエラーを貼り付け – Randroid

+0

おかげ応答のために、私は何もしていないよ、私はチェックして、私に解決策を教えてください –

答えて

0

、以下のようにコードを修正..

** Java Code ** 

FTPClient ObjFtpCon = new FTPClient(); 
       try 
       { 
        ObjFtpCon.connect(strIp); 
        if (ObjFtpCon.login(strFtpUser, strFtpPwd)) 
        { 
         ObjFtpCon.enterLocalPassiveMode(); // important! 
         ObjFtpCon.cwd("/QIA/Questions/Hotel/"); 
         String[] strArrQuesFiles=ObjFtpCon.listNames(); 
         int intcnt=0; 
         boolean blnresult = false; 
         File objfile=new File(getFilesDir().getAbsolutePath()+ "/Questions"); 
         if(!objfile.exists())objfile.mkdirs(); 
         objfile=null; 
         for(intcnt=0;intcnt<strArrQuesFiles.length;intcnt++) 
         { 
          objfile=new File(getFilesDir().getAbsolutePath()+ File.separator + "/Questions/" + strArrQuesFiles[intcnt]); 
          objfile.createNewFile(); 
          //ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes()); 
          FileOutputStream objFos=new FileOutputStream(objfile); 
          blnresult=ObjFtpCon.retrieveFile(strArrQuesFiles[intcnt] , objFos); 
          objFos.close(); 
         } 

         // boolean result = con.storeFile("/QIA/Response/test/Responses.xml", in); 
         if (blnresult) dlgAlert.setMessage("Questions Are Successfully Downloaded").create().show(); 
        } 
       } 
       catch (Exception e) 
       { 
        e.printStackTrace(); 
       } 


       try 
       { 
        ObjFtpCon.logout(); 
        ObjFtpCon.disconnect(); 
       } 
       catch (IOException e) 
       { 
        e.printStackTrace(); 
       } 

      } 
関連する問題