2012-07-06 130 views
1

大家好,任何Java怪胎可以幫助我嗎?我需要上傳一個包含子文件夾的文件夾到我的ftp。 我找到了一些示例代碼,但僅適用於singel文件。 而我不知道如何改變它上傳文件夾。我使用谷歌,但沒有找到任何連接。Ftp從sdcard上傳文件夾到FTP Android

 String server = "192.168.1.2"; 
    String username = "test"; 
    String password = "test"; 
    String local = "mnt/sdcard/shopinglist/"; #This path i need to upload 

    FTPClient ftp = new FTPClient(); 
    try 
    { 
     System.out.println("Connecting"); 
     ftp.connect(server); 
     if(!ftp.login(username, password)) 
     { 
      System.out.println("Login failed"); 
      ftp.logout(); 
      return; 
     } 
     int reply = ftp.getReplyCode(); 
     System.out.println("Connect returned: " + reply); 
     if (!FTPReply.isPositiveCompletion(reply)) { 
      ftp.disconnect(); 
      System.out.println("Connection failed"); 
      return; 
     } 
     ftp.enterLocalPassiveMode(); 
     FileInputStream in = new FileInputStream(local); 
     ftp.setFileType(ftp.BINARY_FILE_TYPE); 
     System.out.println("Uploading File"); 
     boolean store = ftp.storeFile("mnt/sdcard/shopinglist/",in); # ??? Any help ??? 
     in.close(); 
     ftp.logout(); 
     ftp.disconnect(); 
    } 
    catch(Exception ex) 
    { 
     ex.printStackTrace(); 
    } 
} 

}

感謝所有。

+0

推......任何人都可以請幫助 – user1432588 2012-07-07 13:14:34

+0

2天沒有消息-.-°它是真的這麼難去做這個 ?即時通訊非常新的Android的Java開發,但我們只需要列出文件夾上的項目,並將其上傳文件file.Any idee極客開發? – user1432588 2012-07-08 12:55:41

回答

0

請檢查下面的代碼,如果它有助於

Intent intent = new Intent(); 
    intent.setAction(Intent.ACTION_PICK); 
    // FTP URL (Starts with ftp://, sftp:// or ftps:// followed by hostname and port). 
    Uri ftpUri = Uri.parse("ftp://yourftpserver.com"); 
    intent.setDataAndType(ftpUri, "vnd.android.cursor.dir/lysesoft.andftp.uri"); 
    // FTP credentials (optional) 
    intent.putExtra("ftp_username", "anonymous"); 
    intent.putExtra("ftp_password", "[email protected]"); 
    //intent.putExtra("ftp_keyfile", "/sdcard/dsakey.txt"); 
    //intent.putExtra("ftp_keypass", "optionalkeypassword"); 
    // FTP settings (optional) 
    intent.putExtra("ftp_pasv", "true"); 
    //intent.putExtra("ftp_resume", "true"); 
    //intent.putExtra("ftp_encoding", "UTF8"); 
    // Upload 
    intent.putExtra("command_type", "upload"); 
    // Activity title 
    intent.putExtra("progress_title", "Uploading folder ..."); 
    intent.putExtra("local_file1", "/sdcard/localfolder"); 
    // Optional initial remote folder (it must exist before upload) 
    intent.putExtra("remote_folder", "remotefolder/uploadedfolder"); 
    startActivityForResult(intent, 2); 

讓我知道,如果它可以幫助