2014-03-07 60 views

回答

0
USE THIS : 

public void goforIt(){ 


    FTPClient con = null; 

    try 
    { 
     con = new FTPClient(); 
     con.connect("192.168.2.57"); //Your server IP 

     if (con.login("Administrator", "KUjWbk")) //Your Login Creadentials 
     { 
      con.enterLocalPassiveMode(); // important! 
      con.setFileType(FTP.BINARY_FILE_TYPE); 
      String data = "/sdcard/vivekm4a.m4a";  

      FileInputStream in = new FileInputStream(new File(data)); 
      boolean result = con.storeFile("/vivekm4a.m4a", in); 
      in.close(); 
      if (result) Log.v("upload result", "succeeded"); 
      con.logout(); 
      con.disconnect(); 
     } 
    } 
    catch (Exception e) 
    { 
     e.printStackTrace(); 
    } 
+0

但它的一個文件夾內。在此代碼你上傳的文件..'/ SD卡/ vivekm4a.m4a' .. – NirPes

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); 
+0

好吧..我怎麼能做到這一點意圖? (我必須在服務內部完成) – NirPes

+0

Wiil可以在服務中工作嗎? – NirPes

+0

但是'vnd.android.cursor.dir/lysesoft.andftp.uri'在哪裏?... – NirPes

相關問題