Hey Tom,

Try my modified code, you will get succeeded.
boolean isImgUploaded = false;
FTPClient imgUploadClient = new FTPClient();
imgUploadClient.setDefaultTimeout(1000*180);
int reply = 0;
try {

imgUploadClient.connect(AppHelper.FTP_SERVER_HOST,
AppHelper.FTP_SERVER_PORT);
if (imgUploadClient.login(AppHelper.FTP_USER,
AppHelper.FTP_USER_PWD)) {
Log.i(AppHelper.APP_TAG, "Login successful.");
} else
Log.i(AppHelper.APP_TAG, "Login failed.");

reply = imgUploadClient.getReplyCode();
Log.i(AppHelper.APP_TAG, "Reply from server - " + reply);

if (FTPReply.isPositiveCompletion(reply)) {
Log.i(AppHelper.APP_TAG,
"Connected to online storage successful.");

imgUploadClient.setFileType(FTP.BINARY_FILE_TYPE);
imgUploadClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
FileInputStream imgIpStream = new FileInputStream(
request.getImgFile());

long startTime = System.currentTimeMillis();
imgUploadClient.enterLocalPassiveMode();
isImgUploaded = imgUploadClient.storeFile(request.getImgFile().getName(),
imgIpStream);
long endTime = System.currentTimeMillis();
Log.e(AppHelper.APP_TAG, String.format(
" File uploaded in %s seconds",
TimeUnit.SECONDS.toSeconds(endTime - startTime)));

if (isImgUploaded) {
imgIpStream.close();
Log.i(AppHelper.APP_TAG,
"Image upload to online storage successful.");
Log.i(AppHelper.APP_TAG, "Local copy of the image removed.");
response = AppHelper.getErrResponse(AppHelper.SUCCESS,
AppHelper.ERR_CODE_0000, AppHelper.ERR_MSG_0000);
} else {
imgIpStream.close();
reply = imgUploadClient.getReplyCode();
response = AppHelper.getErrResponse(
AppHelper.FAILURE,
AppHelper.ERR_CODE_1002 + "_" + reply,
AppHelper.ERR_MSG_1002
+ imgUploadClient.getReplyString());
}

} else {
Log.e(AppHelper.APP_TAG,
"Failed to connect to online storage successful.");
 response = AppHelper.getErrResponse(AppHelper.FAILURE,
AppHelper.ERR_CODE_1000 + "_" + reply,
AppHelper.ERR_MSG_1001);
}

} catch (SocketException e) {
 Log.e(AppHelper.APP_TAG, AppHelper.ERR_MSG_1008+" - "+e.getMessage());
e.printStackTrace();

} catch (IOException e) {
 Log.e(AppHelper.APP_TAG, AppHelper.ERR_MSG_1009+" - "+e.getMessage());
e.printStackTrace();
} finally {
if(isImgUploaded){
response =
AppHelper.getErrResponse(AppHelper.SUCCESS,AppHelper.ERR_CODE_0000,
AppHelper.ERR_MSG_0000);
}else{
 response = AppHelper.getErrResponse(AppHelper.FAILURE,
AppHelper.ERR_CODE_1000, AppHelper.ERR_MSG_1000);
}
 if (imgUploadClient != null && imgUploadClient.isConnected()) {
try {
imgUploadClient.logout();
imgUploadClient.disconnect();
} catch (IOException e) {
Log.e(AppHelper.APP_TAG, AppHelper.ERR_MSG_1010+" - "+e.getMessage());
e.printStackTrace();
}
}

}


Let me know if it works.

Warm Regards,
*Mukesh Kumar*,
Android Consultant/Freelancer,
India,Hyderabad.




On Sat, Dec 31, 2011 at 1:26 AM, tbellens <[email protected]> wrote:

> Hello ,
> currently I'm writing an android application that needs a file on a
> ftp-server (drivehq) to operate properly .
> Because the ftpclient of sun doesn't work for android ,I used the
> ftpclient of apache.commons .
> When i debug up my app on the device (htc wildfire)  , it gives me an
> IO-message who just says : "ERROR: ftp.drivehq.com" ;
> I don't understand this problem an I'm pretty new to developping
> android apps .
>
> package me.Test.test;
>
> import java.io.IOException;
> import java.net.InetAddress;
> import java.net.InetSocketAddress;
> import java.net.SocketAddress;
> import java.net.UnknownHostException;
>
> import android.app.Activity;
> import org.apache.commons.net.ftp.*;
> import android.os.Bundle;
> import android.widget.TextView;
>
> public class TestActivity extends Activity {
>    private String serverIP  ;
>    @Override
>    public void onCreate(Bundle savedInstanceState) {
>        super.onCreate(savedInstanceState);
>        setContentView(R.layout.main);
>        try {
>
>        FTPClient ftpclient = new  FTPClient() ;
>        TextView tv = new TextView(this) ;
>        tv.setText("Looking for server ip-address...");
>      setContentView(tv);
>                InetAddress ftpaddr = InetAddress.getByName("
> ftp.drivehq.com");
>        ftpclient.connect(ftpaddr ) ;
>
>        ftpclient.login("username","password" ) ;
>
>        setContentView(tv) ;
>        ftpclient.changeWorkingDirectory("/ServerAddress");
>        String[] name = ftpclient.listNames() ;
>        tv.setText(name[1]) ;
>        setContentView(tv) ;
>        }
>        catch (IOException e) {
>                TextView tv1 = new TextView(this) ;
>                tv1.setText("ERROR: " + e.getMessage()) ;
>                setContentView(tv1) ;
>                System.out.println(e.getMessage()) ;
>                e.printStackTrace() ;
>        }
>
>    }
>    public void getServerIp() {
>
>    }
> }
>
> Greetings Tom
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




--

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to