Example for Upload image into the ftp server in Android
HI all,please find the below code for image uploading in ftp server and also refer this link http://www.jibble.org/simpleftp/
package com.eminosoft.upload;
import java.io.File;
import org.apache.commons.net.ftp.FTPClient;
import org.jibble.simpleftp.SimpleFTP;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity {
FTPClient ftpClient;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main);
UploadVideo async = new UploadVideo();
async.execute();
}
class UploadVideo extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
// ftpClient=uploadingFilestoFtp();
try {
SimpleFTP ftp = new SimpleFTP();
ftp.connect("ftp.somewhere.net", 21, "username", "password");
ftp.bin();
// Change to a new working directory on the FTP server.
ftp.cwd("web");
// Upload some files.
ftp.stor(new File("/mnt/sdcard/A.png"));
// 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();
}
}
}
HI all,please find the below code for image uploading in ftp server and also refer this link http://www.jibble.org/simpleftp/
package com.eminosoft.upload;
import java.io.File;
import org.apache.commons.net.ftp.FTPClient;
import org.jibble.simpleftp.SimpleFTP;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity {
FTPClient ftpClient;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main);
UploadVideo async = new UploadVideo();
async.execute();
}
class UploadVideo extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
// ftpClient=uploadingFilestoFtp();
try {
SimpleFTP ftp = new SimpleFTP();
ftp.connect("ftp.somewhere.net", 21, "username", "password");
ftp.bin();
// Change to a new working directory on the FTP server.
ftp.cwd("web");
// Upload some files.
ftp.stor(new File("/mnt/sdcard/A.png"));
// 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();
}
}
}
hii, i have tried your code to connect to ftp and upload file on working directory but I am getting exception as:
ReplyDelete06-24 10:37:01.435: W/System.err(1243): java.io.IOException: SimpleFTP received an unknown response when connecting to the FTP server: 220-FileZilla Server version 0.9.41 beta
could you please help.
Save my life! Tks friend!
ReplyDelete