2013-07-09 66 views
2

你好我想上傳一個像4MB或類似的東西的小文件用apache commons ftpclient它不會上傳我的文件,並且不會給我錯誤,並說上傳成功 這是我的代碼,請幫助我感謝名單提前.. 這裏去的代碼..ftpclient不會上傳我的文件

new Thread(new Runnable() { 
      public void run() { 
       Looper.prepare(); 

       FTPClient client = new FTPClient(); 

       try { 
         boolean result = false; 
         FileInputStream fis = null; 

         client.connect(server); 
         client.enterLocalPassiveMode(); 
         client.login(user, pass); 
         client.makeDirectory("/public_html/"+str); ///str is a name of remote folder 

         client.setFileType(FTP.BINARY_FILE_TYPE); 
         client.setFileTransferMode(FTP.BINARY_FILE_TYPE); 
         client.changeWorkingDirectory(str); 
         String path1 = Environment.getExternalStorageDirectory() + "/index.htm"; 
         File f = new File(path1); 
         String testname = f.getName(); 

         fis = new 
           FileInputStream(f); 
         result = client.storeFile(testname, fis); 

         if (result == true){ 
          Log.v("upload","upload successfull"); 
         } 
         else{ 
          Log.v("upload", "upload failed"); 
         } 
       catch (Exception e) { 
         e.printStacktrace(); 
       } 
      } 
      }).start(); 

回答

1
client.changeWorkingDirectory(str); 

是它可能是str目錄不存在,因爲你所創建的目錄是"/public_html/"+str

+0

str是從Edittext –

+0

的輸入中創建的目錄的名稱是的,我明白這一點。我只是說在client.makeDirectory(「/ public_html /」+ str);'和'client.changeWorkingDirectory(str);'之間存在不一致。 – njzk2

+0

我想創建一個名爲str的dir,然後將工作目錄更改爲str,並上傳我的文件index.htm –