My application is uploading the file from SD Card to the directory on FileZilla FTP Server. After running my appliaction it gives me exception which I am unable to resolve after so many searches.
here is the log cat output:
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)
and this is my code for the 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();
}
}
It seems that the SimpleFTP library implementation is not conforming to the FTP specification (RFC 959). According to the source found here it expects the initial reply of the FTP server to start with
"220 "
while the RFC specifies that [an] FTP reply consists of a three digit number (transmitted as three alphanumeric characters) followed by some text. So a reply starting with"220-"
is allowed.I suggest using a better FTP library such as apache commons ftp or ftp4j.
After so many days i worked on this thing again and successfuly got the things working. So, I am posting my answer.Hope it would help some one.
This is my Main Activity Code:
Please check the log cat while your application is running you will get to know how this is working. Thanks.