Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download a file from FTP server to Android device?

Tags:

android

ftp

I have a requirement to download a image from FTP server to android device. I tried with few samples by using ftp4j-1.7.2.jar library, but failed to connect with FTP servers & messed up.

Have anyone worked with FTP servers?

Please suggest to make connection & download file from Server.

like image 651
Anil kumar Avatar asked Jul 07 '14 07:07

Anil kumar


People also ask

How to use FTP on Android?

Android Use FTP 1 Download a Third-party FTP App. As mentioned above, you need to have an FTP app on your Android. Some file explorers such as ES File ... 2 Connect to the Same Wi-Fi Network. 3 Start FTP Service. 4 Open the FTP Link on Your PC. See More....

How to upload files using FTP in Linux?

Upload Files Using FTP 1 Connect to FTP Server via Command Line. To connect to any FTP server from windows open its command prompt and for Linux open terminal window ... 2 Upload Single File to FTP Server. 3 Download A Single File from FTP. 4 Upload Multiple Files to FTP. 5 Download Multiple Files from FTP. See More....

How do I download files from Android to my computer?

You can only download your Android files to PC. To access files from the Chrome, enter the FTP URL in the address bar of Chrome and press enter. To perform actions like upload, move or rename, you can use the File Explorer on your PC or download an FTP application like FileZilla.

How do I download a file from an FTP server?

One of my recent tasks has been to download a file from an FTP server. The recommended solution is to use the Apache Commons Net library for that, which supports FTP among many others protocols. Adding it to the project was as easy as putting the jar into the libs/ directory.


1 Answers

Use library commons.apache.org/proper/commons-net

Check below code to download file from FTP server:

private Boolean downloadAndSaveFile(String server, int portNumber,
    String user, String password, String filename, File localFile)
    throws IOException {
FTPClient ftp = null;

try {
    ftp = new FTPClient();
    ftp.connect(server, portNumber);
    Log.d(LOG_TAG, "Connected. Reply: " + ftp.getReplyString());

    ftp.login(user, password);
    Log.d(LOG_TAG, "Logged in");
    ftp.setFileType(FTP.BINARY_FILE_TYPE);
    Log.d(LOG_TAG, "Downloading");
    ftp.enterLocalPassiveMode();

    OutputStream outputStream = null;
    boolean success = false;
    try {
        outputStream = new BufferedOutputStream(new FileOutputStream(
                localFile));
        success = ftp.retrieveFile(filename, outputStream);
    } finally {
        if (outputStream != null) {
            outputStream.close();
        }
    }

    return success;
} finally {
    if (ftp != null) {
        ftp.logout();
        ftp.disconnect();
    }
}
}
like image 191
Anil Jadhav Avatar answered Oct 01 '22 04:10

Anil Jadhav