FTPS connection in android

I am new to android, i want to download the files from FTPs server, On emulater i am able to download files but when i try on target board it is giving error at ftp.auth(SSLFTPClient.AUTH_TLS);

Below is the my code, please suggest me where i am wrong.

package com.android.ftp;

import java.io.File;

import android.app.Activity;
import android.os.Bundle;

import com.enterprisedt.net.ftp.FTPClientInterface;
import com.enterprisedt.net.ftp.FTPConnectMode;
import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.ssl.SSLFTPClient;
import com.enterprisedt.util.debug.Level;
import com.enterprisedt.util.debug.Logger;

public class Ftp_testActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    String host = "ftp.xyz.com";
    String username = "abcd";
    String password = "pqr";
    String filename = "/mnt/sdcard/video1/747.3gp";


    // set up logger so that we get some output
    Logger log = Logger.getLogger(Ftp_testActivity.class);
    Logger.setLevel(Level.INFO);

    SSLFTPClient ftp = null;


    try {
        // create client
        log.info("Creating FTPS (explicit) client");
        ftp = new SSLFTPClient();

        // disable standard SSL closure
        log.info("Setting configuration flags");
        ftp.setConfigFlags(SSLFTPClient.ConfigFlags.DISABLE_SSL_CLOSURE);


        // set remote host
        log.info("Setting remote host");
        ftp.setRemoteHost(host);
        ftp.setRemotePort(21);

        // turn off server validation
        log.info("Turning off server validation");
        ftp.setValidateServer(false);

        // connect to the server
        log.info("Connecting to server " + host);
        ftp.connect();

        // switch to SSL on control channel
        log.info("Switching to FTPS (explicit mode)");
        ftp.auth(SSLFTPClient.AUTH_TLS);

        // log in
        log.info("Logging in with username=" + username + " and password="
                + password);
        ftp.login(username, password);
        log.info("Logged in");

        ftp.setConnectMode(FTPConnectMode.PASV);
        ftp.setType(FTPTransferType.ASCII);

        putGetDelete(filename, ftp);
        log.info("Successfully transferred in ASCII mode");

        // Shut down client
        log.info("Quitting client");
        ftp.quit();

        log.info("Example complete");

    } catch (Exception e) {
        e.printStackTrace();
    }
  }


  private static void putGetDelete(String name, FTPClientInterface ftp)
        throws Exception {
    ftp.put(name, name);
    ftp.get(name + ".copy", name);
    ftp.delete(name);
    File file = new File(name + ".copy");
    file.delete();
    }
}

Answers


You should try:

ftp.setRemotePort(990);

where 990 is port SSL default.


Need Your Help

Parsing a URL Using ASP.NET MVC Routing

asp.net-mvc system.web.routing

I have a URL in string format that I want to parse to get the relevent Route Values. I could parse the string manually, but I want to use my routing configuration so I am not tied to the particular

Trying to switch a texture when player dies (OpenGL + C++)

c++ opengl textures texture-mapping

I'm creating a 2D game and when the player dies I want the texture I to switch to another (to show an explosion) I also want the game to pause for a second or two so the user can see that the textu...