Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7893315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:06:06+00:00 2026-06-03T07:06:06+00:00

Hi friends Iam doing an android application in that i want to select one

  • 0

Hi friends
Iam doing an android application in that i want to select one video from my sd card and want to upload it to ftp server.While iam running the project in the emulator i got 04-28 18:22:00.810: ERROR/AndroidRuntime(1053): java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient.Is there any way to solve this problem.I included two jar files org.apache.commons.net.jar and commons-net-1.4.1.jar by right click my project->properties->java build path->add external jars.Even i added the jar files,the project did’nt gets runned.Please help me if anybody knows…
Iam using the below code:

package net.jeema.UploadFTP;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.UUID;

**import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;**

import org.w3c.dom.CharacterData;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class UploadFTPActivity extends Activity {
    SQLiteDatabase myDataBase;
    // public String[] gur = new String[4];

    private static final int SELECT_VIDEO = 1;
    String strXmlResponse, url = null;
    String selectedPath, extension;
    Button bnupload, bnbrowse = null;
    String fname = null;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addnewvideo);
        bnupload = (Button) findViewById(R.id.buttonUpload);
        bnbrowse = (Button) findViewById(R.id.buttonBrowse);
        addVIDEO();
    }

    public void addVIDEO {      
        bnbrowse.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent = new Intent();
                intent.setType("video/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(
                        Intent.createChooser(intent, "Select Video"),
                        SELECT_VIDEO);
            }
        });
    }

    public void onActivityResult(int requestCode, int resultCode,
            final Intent data) {

        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_VIDEO) {
                System.out.println("SELECT VIDEO");
                Uri selectedImageUri = data.getData();
                selectedPath = getPath(selectedImageUri);
                System.out.println("SELECT_VIDEO Path : " + selectedPath);
                int pos = selectedPath.lastIndexOf(".");
                if (pos > 0) {
                    extension = selectedPath.substring(pos + 1);
                }               
                doFileUpload();
            }
        }
    }

    public String getPath(Uri uri) {
        String[] projection = { MediaStore.Video.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }

    public void doFileUpload() {
        bnupload.setOnClickListener(new OnClickListener() {
            final SharedPreferences prefs = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext());

            public void onClick(View arg0) {
                UUID uniqueKey = UUID.randomUUID();
                fname = uniqueKey.toString();
                Log.e("UNIQUE NAME", fname);        
                // TODO Auto-generated method stub
                String hostName = "MY HOST NAME";
                String username = "****";
                String password = "****";
                String location = selectedPath;
                FTPClient ftp = null;

                InputStream in = null;
                try {
                    ftp = new FTPClient();
                    ftp.connect(hostName);
                    ftp.login(username, password);

                    ftp.setFileType(FTP.BINARY_FILE_TYPE);

                    ftp.changeWorkingDirectory("/uploads");

                    int reply = ftp.getReplyCode();
                    System.out.println("Received Reply from FTP Connection:" + reply);

                    if (FTPReply.isPositiveCompletion(reply)) {
                        System.out.println("Connected Success");
                    }

                    File f1 = new File(location);
                    in = new FileInputStream(f1);

                    ftp.storeFile(fname+"."+extension, in);

                    System.out.println("SUCCESS");

                    ftp.logout();
                    ftp.disconnect();
                } catch (Exception e) {
                    e.printStackTrace();
                }           
            }
            public String getCharacterDataFromElement(Element e) {
                Node child = e.getFirstChild();
                if (child instanceof CharacterData) {
                    CharacterData cd = (CharacterData) child;
                    return cd.getData();
                }
                return "";
            }
        });
    }
}

I got the output using simple java program with code below.But i want to do it in android actoivity:

import java.io.File;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;

public class FtpTest {

    public static void main(String args[]) {
        String hostName = "MY HOST NAME";
        String username = "****";
        String password = "****";
        String location = "F:\\droid-samples\\VID-20120421-103134.3gp";
        FTPClient ftp = null;

        InputStream in = null;
        try {
            ftp = new FTPClient();
            ftp.connect(hostName);
            ftp.login(username, password);

            ftp.setFileType(FTP.BINARY_FILE_TYPE);

            ftp.changeWorkingDirectory("/uploads");

            int reply = ftp.getReplyCode();
            System.out.println("Received Reply from FTP Connection:" + reply);

            if (FTPReply.isPositiveCompletion(reply)) {
                System.out.println("Connected Success");
            }

            File f1 = new File(location);
            in = new FileInputStream(f1);

            ftp.storeFile("VID-20120421-103134.3gp", in);

            System.out.println("SUCCESS");

            ftp.logout();
            ftp.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:06:08+00:00Added an answer on June 3, 2026 at 7:06 am

    You could try to solve the 0 bytes issue:

    ftp.enterLocalPassiveMode();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

now I am doing an Android application.I have to read a file from sdcard.I
I am doing one application to read pdf from sdcard through webview. I used
hi friends i am doing here validation for username and password from server database
I am doing an android application. In my project I am checking phonestates using
Hai Friends, I have developed an application which en-composes list views and posted that
friends I am new to iphone development, I have mostly worked with Android, now
I am developing an iPhone application that will send sms the logged in user
I am currently writing a application that will eventually be going to market, but
friends, i dont see serbain language in android phone language settings.... i am using
I am working with Android Facebook SDK and wanted to get a friends list.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.