2014-06-24 19 views
5

Uygulamam, dosyayı SD Karttan FileZilla FTP Server'daki dizine yüklüyor. Uygulamamı çalıştırdıktan sonra bu kadar çok aramadan sonra çözemediğim istisnalar veriyor. (SD Karttan FileZilla Server'a dosya yükleme

06-24 11:06:53.715: W/System.err(1304): java.io.IOException: SimpleFTP received an unknown response when connecting to the FTP server: 220-FileZilla Server version 0.9.41 beta 
06-24 11:06:54.055: W/System.err(1304):  at org.jibble.simpleftp.SimpleFTP.connect(SimpleFTP.java:74) 
06-24 11:06:54.087: W/System.err(1304):  at com.example.upload1.MainActivity$UploadVideo.doInBackground(MainActivity.java:63) 
06-24 11:06:54.167: W/System.err(1304):  at com.example.upload1.MainActivity$UploadVideo.doInBackground(MainActivity.java:1) 
06-24 11:06:54.167: W/System.err(1304):  at android.os.AsyncTask$2.call(AsyncTask.java:287) 
06-24 11:06:54.167: W/System.err(1304):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
06-24 11:06:54.167: W/System.err(1304):  at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
06-24 11:06:54.167: W/System.err(1304):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
06-24 11:06:54.167: W/System.err(1304):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 
06-24 11:06:54.403: W/System.err(1304):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
06-24 11:06:54.403: W/System.err(1304):  at java.lang.Thread.run(Thread.java:856) 

ve bu SimpleFTP kütüphane uygulaması FTP şartnamesine uygun olmadığını görünüyor MainActivity.java

import java.io.File; 

    import org.jibble.simpleftp.SimpleFTP; 

    import android.app.Activity; 
    import android.os.AsyncTask; 
    import android.os.Bundle; 
    import android.os.Environment; 
    import android.view.View; 
    import android.view.View.OnClickListener; 
    import android.widget.Button; 
    import android.widget.Toast; 
    //import com.kpbird.ftpdemo.R; 




    public class MainActivity extends Activity implements OnClickListener { 
     //FTPClient client; 


    /********* work only for Dedicated IP ***********/ 
    static final String FTP_HOST= "203.199.134.131"; 

    /********* FTP USERNAME ***********/ 
    static final String FTP_USER = "a_gupta"; 

    /********* FTP PASSWORD ***********/ 
    static final String FTP_PASS ="AditI123"; 

    Button btn; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     btn = (Button) findViewById(R.id.button1); 
     btn.setOnClickListener(this); 
    } 
    public void onClick(View v) { 
     UploadFile async = new UploadFile(); 
     async.execute(); 

     } 

     class UploadFile extends AsyncTask<String, Integer, String> { 

     @Override 
     protected String doInBackground(String... params) { 
     // ftpClient=uploadingFilestoFtp(); 
     try { 
     SimpleFTP ftp = new SimpleFTP(); 

     ftp.connect(FTP_HOST, 21, FTP_USER, FTP_PASS); 

     ftp.bin(); 

     // Change to a new working directory on the FTP server. 
     ftp.cwd("callrecording"); 

     // Upload some files. 
     ftp.stor(new File(Environment.getExternalStorageDirectory().getParent() + "/invite_json.txt")); 
     // ftp.stor(new File("comicbot-latest.png")); 

     // You can also upload from an InputStream, e.g. 
     // ftp.stor(new FileInputStream(new File("test.png")), 
     // "test.png"); 
     // ftp.stor(someSocket.getInputStream(), "blah.dat"); 

     // Quit from the FTP server. 
     ftp.disconnect(); 

     } catch (Exception e) { 
     e.printStackTrace(); 
     } 

     return null; 
     } 

     @Override 
     protected void onPreExecute() { 
     super.onPreExecute(); 
     // dialog.show(); 
     } 

     @Override 
     protected void onPostExecute(String result) { 
     // TODO Auto-generated method stub 
     super.onPostExecute(result); 
     Toast.makeText(MainActivity.this, "sent", Toast.LENGTH_LONG).show(); 
     } 
     } 
+0

i benim appliaction' çalıştırdıktan sonra '... – KOTIOS

+0

doesnt iletişime ... Yukarıdaki kimlik bilgileri ile bağlanmak için tryied? Şunu mu demek istediniz: 'AsyncTask'ımı yürütürken? FTPClient bağlanamıyor belirsiz. Şikayet yanıtla ilgili. Ve bir cevap sadece bağlantıdan sonra orada olabilir ... 'Dedicated IP için sadece çalışmakla ne demek istiyorsun? Sunucu sadece güvenilir istemci iplerini kabul ediyor mu? Kodunuzun hangi satırları çalıştırılır? Öğrenmek için Log.d() başlangıçlarını ekleyin. – greenapps

+0

Yukarıdaki kod yani özel IP çalışması, IP'yi bir defada bir IP adresi olan FTP_HOST içinde tanımlamamız gerektiği anlamına gelir. Ve benim app çalıştırdıktan sonra düğme tıklama olayı sonrası anlamıyorum – Adi

cevap

0

benim kodudur: Burada

günlük kedi çıkışı RFC 959). Kaynağa göre bu RFC [bir] FTP cevap metin tarafından takip üç basamaklı bir sayı (üç alfanümerik karakter olarak gönderilir) oluşur belirtir iken FTP sunucusuna ilk cevap "220 " ile başlamasını beklediğini here bulundu. "220-" ile başlayan bir cevaba izin verilir.

Daha iyi bir FTP kütüphane gibi apache commons ftp veya ftp4j kullanmanızı öneririz. ben yine bu şeyde çalıştı ve başarıyla çalışan şeyler var bu kadar çok gün sonra

+0

Yorumunuz için teşekkürler, ancak daha önce denedim. Lütfen yeni bir şeyleri bana sunun. – Adi

+0

Tam olarak ne denediniz? –

+0

i Her iki kütüphaneyi de denediniz ancak her iki kütüphaneyle de bağlantı kurulamadı. Ve emin değilim ama sorun olabilir FTP sunucusu ve FileZilla Server'a bağlanırken farkın olmasıdır. Yani, no. Portunu değiştirmeye çalıştım. 425'e (transferler için filezilla tarafından desteklenir.) ve şimdi ConnectException hatası alıyorum – Adi

1

. Yani, cevabımı gönderiyorum.

Bu benim Ana Aktivite Kodu şudur: uygulama bu nasıl çalıştığını bilmek alacak çalışırken

package com.example.ftpup; 

import it.sauronsoftware.ftp4j.FTPAbortedException; 
import it.sauronsoftware.ftp4j.FTPClient; 
import it.sauronsoftware.ftp4j.FTPDataTransferException; 
import it.sauronsoftware.ftp4j.FTPDataTransferListener; 
import it.sauronsoftware.ftp4j.FTPException; 
import it.sauronsoftware.ftp4j.FTPIllegalReplyException; 

import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.OutputStream; 

import android.app.Activity; 
import android.app.Dialog; 
import android.app.ProgressDialog; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.os.Environment; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.Toast; 

public class MainActivity extends Activity implements OnClickListener { 


    /********* work only for Dedicated IP ***********/ 
    static final String FTP_HOST= "203.199.134.131"; 

    /********* FTP USERNAME ***********/ 
    static final String FTP_USER = "a_gupta"; 

    /********* FTP PASSWORD ***********/ 
    static final String FTP_PASS ="AditI123"; 
    public static final int DIALOG_DOWNLOAD_PROGRESS = 0; 
    Button btn; 
    FTPClient client = new FTPClient(); 
    private ProgressDialog mProgressDialog; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     btn = (Button) findViewById(R.id.uploadButton); 
     btn.setOnClickListener(this); 

    } 

    public void onClick(View v) { 


     startDownload(); 
    } 
    // /******* Used to file upload and show progress **********/ 




     private void startDownload() { 
      //Pick file 
      //File f = new File("/sdcard/invite_json.txt"); 
      // Async task 

      new DownloadFileAsync().execute(); 
     } 
     @Override 
     protected Dialog onCreateDialog(int id) { 
      switch (id) { 
      case DIALOG_DOWNLOAD_PROGRESS: 
       mProgressDialog = new ProgressDialog(this); 
       mProgressDialog.setMessage("Downloading file.."); 
       mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
       mProgressDialog.setCancelable(false); 
       mProgressDialog.show(); 
       return mProgressDialog; 
      default: 
       return null; 
      } 
     } 
     // Upload sdcard file 


    //public void uploadFile(File fileName){ 

    class DownloadFileAsync extends AsyncTask<String, String, String> { 
     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      showDialog(DIALOG_DOWNLOAD_PROGRESS); 


     }@Override 
     protected String doInBackground(String... filename) { 
      String sdcard = Environment.getExternalStorageDirectory().toString(); 
      File file = new File(sdcard+"/androrec/"); 
      //File file2 = new File("/mnt/sdcard/CallRecorderBackup"); 

      File[] listofFiles = file.listFiles(); 
      Log.d("No. of files" ,fileArrayToString(listofFiles)); 
      try{ 
       client.connect(FTP_HOST,21); 



      for (int i = 0; i <=listofFiles.length ; i++) { 


        Log.d("Tag 4", "inside of ftp connect"); 

       Log.d("Tag 1", "inside of for loop"); 

       if (listofFiles == null || listofFiles[i].isFile()) { 
        Log.d("Tag 2", "inside of if"); 
        String files = listofFiles[i].getName(); 
        Log.d("Tag 3", "inside of files"); 

        File filetoload = new File(sdcard+"/androrec/"+files); 
        String uploadingFiles = filetoload.toString(); 
        Log.d("Files uploading to the server", uploadingFiles); 
        client.login(FTP_USER, FTP_PASS); 
          //client.connect(FTP_HOST,21); 
          Log.d("Tag 4", "inside of ftp connect"); 

         Log.d("Tag 5", "inside of for ftp pass"); 
         //client.setType(FTPClient.TYPE_BINARY); 
         //client.changeDirectory("/"); 
         Log.d("Tag 6", "inside of for dir"); 

        client.upload(filetoload); 
        Log.d("Tag 7", "inside of download"); 
        //out.write(buf, 0, len); 
       //} 
       //} 






      // client.upload(in, new MyTransferListener()); 

     } 
       else{ 

       } 
       //client.disconnect(true); 
       } 
      } 

       catch (IllegalStateException | IOException 
         | FTPIllegalReplyException | FTPException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } catch (FTPDataTransferException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } catch (FTPAbortedException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 


      try { 
       client.disconnect(true); 
      } catch (Exception e2) { 
       e2.printStackTrace(); 
      } 
      return null; 
      } 



      /*} 
      }*/ 

     @Override 
     protected void onPostExecute(String unused) { 
      dismissDialog(DIALOG_DOWNLOAD_PROGRESS); 
     } 

    } 

    // } 
    String fileArrayToString(File[] f){ 
     String output = ""; 
     String delimiter = "\n" ;// Can be new line \n tab \t etc... 
     for (int i=0; i<f.length; i++) 
     { 
      output = output + f[i].getPath() + delimiter; 
     } 

     return output; 
    } 

} 

günlük kedi kontrol edin. Teşekkürler.