2016-06-20 8 views
-1

Ich möchte Bild auf FTP hochladen mit einfachen FTP. Es konnte jedoch immer nicht auf FTP hochgeladen werden. Der Fehler zeigt immer auf ftp.connect. Ich weiß nicht warum. Also ich hoffe du kannst mir helfen. Bitte. Danke im Voraus. Upload.javaFehler beim Hochladen auf FTP mit Hilfe von simpleFTP

public class ImageUpdate extends AppCompatActivity { 
     private static final String TAG_ID = "id"; 
     private static final String TAG_PESAN = "message"; 
     private static final String TAG_HASIL = "result"; 
     private static final String TAG_IMAGE_ID = "id_image"; 
     private static final String TAG_IMAGE_NAME= "image_name"; 
     ProgressDialog pDialog; 

     JSONParser jparser = new JSONParser(); 
     ArrayList<HashMap<String, String>> namelist, idList, imageList; 
     JSONArray names, names1, names2; 

     private static int RESULT_LOAD_IMG = 1; 
     String imgDecodableString = null; 
     Button submit; 


     static final String FTP_HOST = "xxxxxxxxxx"; 
     static final String FTP_USER = "xxxxxxxxxxxx"; 
     static final String FTP_PASS = "xxxxxxxxxxx"; 
     String name, vid; 
     /** 
     * ATTENTION: This was auto-generated to implement the App Indexing API. 
     * See https://g.co/AppIndexing/AndroidStudio for more information. 
     */ 
     private GoogleApiClient client2; 

     SessionManagement session; 
     String nm,addr,pos,tlp,mail,usr,pass,id,image; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_image_update); 

      getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
      getSupportActionBar().setHomeButtonEnabled(true); 
      client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
      session =new SessionManagement(ImageUpdate.this); 
      HashMap<String, String> user = session.getUserDetails(); 
      id=user.get(SessionManagement.KEY_ID); 
      nm=user.get(SessionManagement.KEY_NAME); 
      addr=user.get(SessionManagement.KEY_ALAMAT); 
      mail=user.get(SessionManagement.KEY_EMAIL); 
      tlp=user.get(SessionManagement.KEY_TELP); 
      usr=user.get(SessionManagement.KEY_USERNAME); 
      pass=user.get(SessionManagement.KEY_PASS); 
      submit=(Button) findViewById(R.id.buttonUploadPicture); 
      submit.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        if (imgDecodableString == null) { 
         Toast.makeText(ImageUpdate.this, "Choose image first, please", Toast.LENGTH_LONG); 
        } else { 
         File f = new File(imgDecodableString); 
         name = f.getName(); 
         uploadFile(f); 
        } 
       } 
      }); 

     } 
     public void loadImagefromGallery(View view) { 
      // Create intent to Open Image applications like Gallery, Google Photos 
      Intent galleryIntent = new Intent(Intent.ACTION_PICK, 
        MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
      // Start the Intent 
      startActivityForResult(galleryIntent, RESULT_LOAD_IMG); 
     } 

     @Override 
     protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
      super.onActivityResult(requestCode, resultCode, data); 
      try { 
       // When an Image is picked 
       if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK 
         && null != data) { 
        // Get the Image from data 


        Uri selectedImage = data.getData(); 
        String[] filePathColumn = {MediaStore.Images.Media.DATA}; 

        // Get the cursor 
        Cursor cursor = getContentResolver().query(selectedImage, 
          filePathColumn, null, null, null); 
        // Move to first row 
        cursor.moveToFirst(); 

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
        String filename = cursor.getString(columnIndex); 
        imgDecodableString = cursor.getString(columnIndex); 
        cursor.close(); 

        File f = new File("" + imgDecodableString); 
        f.getName(); 
        ImageView imgView = (ImageView) findViewById(R.id.imgView); 
        // Set the Image in ImageView after decoding the String 
        imgView.setImageBitmap(BitmapFactory 
          .decodeFile(imgDecodableString)); 

       } else { 
        Toast.makeText(this, "Pilih Bukti Transaksi", 
          Toast.LENGTH_LONG).show(); 
       } 
      } catch (Exception e) { 
       Toast.makeText(this, "Failed to Choose", Toast.LENGTH_LONG) 
         .show(); 
      } 
     } 

     public void uploadFile(File fileName) { 

      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
      StrictMode.setThreadPolicy(policy); 
      SimpleFTP ftp=new SimpleFTP(); 

      try { 
       ftp.connect("xxxxxxx", 21, "xxxxxxxx", "xxxxxxx"); 
       ftp.bin(); 
       ftp.cwd("img/imageProfil/"); 
       ftp.stor(fileName); 
       ftp.disconnect(); 

      } catch (Exception e) { 
       e.printStackTrace(); 
       try { 
        ftp.disconnect(); 
        Toast.makeText(ImageUpdate.this, "disconnect", Toast.LENGTH_LONG).show(); 
       } catch (Exception e2) { 
        e2.printStackTrace(); 
        Toast.makeText(ImageUpdate.this, "failed", Toast.LENGTH_LONG).show(); 
       } 
      } 

     } 

     @Override 
     public void onStart() { 
      super.onStart(); 

      // ATTENTION: This was auto-generated to implement the App Indexing API. 
      // See https://g.co/AppIndexing/AndroidStudio for more information. 
      client2.connect(); 
      Action viewAction = Action.newAction(
        Action.TYPE_VIEW, // TODO: choose an action type. 
        "Upload Page", // TODO: Define a title for the content shown. 
        // TODO: If you have web page content that matches this app activity's content, 
        // make sure this auto-generated web page URL is correct. 
        // Otherwise, set the URL to null. 
        Uri.parse("http://host/path"), 
        // TODO: Make sure this auto-generated app deep link URI is correct. 
        Uri.parse("android-app://com.amobi.newlomapodfix/http/host/path") 
      ); 
      AppIndex.AppIndexApi.start(client2, viewAction); 
     } 

     @Override 
     public void onStop() { 
      super.onStop(); 

      // ATTENTION: This was auto-generated to implement the App Indexing API. 
      // See https://g.co/AppIndexing/AndroidStudio for more information. 
      Action viewAction = Action.newAction(
        Action.TYPE_VIEW, // TODO: choose an action type. 
        "Upload Page", // TODO: Define a title for the content shown. 
        // TODO: If you have web page content that matches this app activity's content, 
        // make sure this auto-generated web page URL is correct. 
        // Otherwise, set the URL to null. 
        Uri.parse("http://host/path"), 
        // TODO: Make sure this auto-generated app deep link URI is correct. 
        Uri.parse("android-app://com.amobi.newlomapodfix/http/host/path") 
      ); 
      AppIndex.AppIndexApi.end(client2, viewAction); 
      client2.disconnect(); 
     } 
    } 

stacktrace

06-20 22:32:00.692 2845-2845/com.amobi.newlomapodfix W/EGL_emulation: eglSurfaceAttrib not implemented 
06-20 22:32:04.900 2845-2845/com.amobi.newlomapodfix W/System.err: java.io.IOException: SimpleFTP received an unknown response when connecting to the FTP server: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ---------- 
06-20 22:32:04.900 2845-2845/com.amobi.newlomapodfix W/System.err:  at org.jibble.simpleftp.SimpleFTP.connect(SimpleFTP.java:74) 
06-20 22:32:04.900 2845-2845/com.amobi.newlomapodfix W/System.err:  at com.amobi.newlomapodfix.UploadActivity.uploadFile(UploadActivity.java:167) 
06-20 22:32:04.900 2845-2845/com.amobi.newlomapodfix W/System.err:  at com.amobi.newlomapodfix.UploadActivity$1.onClick(UploadActivity.java:100) 
06-20 22:32:04.900 2845-2845/com.amobi.newlomapodfix W/System.err:  at android.view.View.performClick(View.java:4204) 
06-20 22:32:04.900 2845-2845/com.amobi.newlomapodfix W/System.err:  at android.view.View$PerformClick.run(View.java:17355) 
06-20 22:32:04.900 2845-2845/com.amobi.newlomapodfix W/System.err:  at android.os.Handler.handleCallback(Handler.java:725) 
06-20 22:32:04.900 2845-2845/com.amobi.newlomapodfix W/System.err:  at android.os.Handler.dispatchMessage(Handler.java:92) 
06-20 22:32:04.900 2845-2845/com.amobi.newlomapodfix W/System.err:  at android.os.Looper.loop(Looper.java:137) 
06-20 22:32:04.900 2845-2845/com.amobi.newlomapodfix W/System.err:  at android.app.ActivityThread.main(ActivityThread.java:5041) 
06-20 22:32:04.900 2845-2845/com.amobi.newlomapodfix W/System.err:  at java.lang.reflect.Method.invokeNative(Native Method) 
06-20 22:32:04.904 2845-2845/com.amobi.newlomapodfix W/System.err:  at java.lang.reflect.Method.invoke(Method.java:511) 
06-20 22:32:04.908 2845-2845/com.amobi.newlomapodfix W/System.err:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
06-20 22:32:04.912 2845-2845/com.amobi.newlomapodfix W/System.err:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
06-20 22:32:04.912 2845-2845/com.amobi.newlomapodfix W/System.err:  at dalvik.system.NativeStart.main(Native Method) 
+0

Es zu folgen scheint ein Problem mit dem Paket zu sein 'org.jibble.simpleftp.SimpleFTP' weil die empfangene Antwort ein normales ist. –

+0

hmm also was soll ich tun? - @MasterDJon –

+0

Verwenden Sie ein anderes Paket, aktualisieren Sie es oder kontaktieren Sie sie. –

Antwort

Verwandte Themen