Read a JSON hosted in an FTP protocol URL

0

I want to do an App with Android Studio to see a JSON hosted on a FTP .

What would that connection be like?

    
asked by Dario Ortiz 01.01.2018 в 01:16
source

1 answer

0

From an external App: You've probably wondered if there was a way to transfer files between your server and your mobile device on the road, where there is not a computer available. Well, this will definitely solve that. You will learn how to transfer files between an FTP server and your Android device with a free application called: AndFTP.

Difficulty level: Easy

  • Download and install the application from the Android Market.

  • Open the application.

  • The first time you start the application, you will be asked to enter the server information you would like to connect to. Enter your server address, username, password and port (usually 21).

  • Touch the connect button.

  • Now it will try a connection to the server. If the connection is successful, you will now see the files on your server, as well as the files on your mobile device.

  • To transfer files, simply touch the file, tap "transfer" and move the selected folder remotely.
  • tutorial in English

    If you like to do it from the code:

    Download the necessary .jar files. First you need to follow the JAR file:

  • commons-net-3.3.jar
  • Download here:

    download

    Download the latest jar file and add it to the libs folder of your Android project.

    Step 2 Class MyFTPClientFunctions Create new MyFTPClientFunctions classes in your project. Now add some FTP functions in the newly created class.

    FTPClient público mFTPClient = null; // Agrega la parte superior de la clase
    

    Now add a method to connect the FTP server. (Method to connect to the FTP server)

    public boolean ftpConnect(String host, String username, String password, int port) {
        try {
            mFTPClient = new FTPClient();
            // connecting to the host
            mFTPClient.connect(host, port);
            // now check the reply code, if positive mean connection success
            if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
                // login using username & password
                boolean status = mFTPClient.login(username, password);
               /*
                   * Set File Transfer Mode
                   * To avoid corruption issue you must specified a correct
                   * transfer mode, such as ASCII_FILE_TYPE, BINARY_FILE_TYPE,
                   * EBCDIC_FILE_TYPE .etc. Here, I use BINARY_FILE_TYPE for
                   * transferring text, image, and compressed files.
                */
                mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
                mFTPClient.enterLocalPassiveMode();
                return status;
            }
        } catch (Exception e) {
            Log.d(TAG, "Error: could not connect to host " + host);
        }
        return false;
    }
    

    Now add a method to disconnect the FTP server. (Method to disconnect from the FTP server)

    public boolean ftpDisconnect() {
        try {
            mFTPClient.logout();
            mFTPClient.disconnect();
            return true;
        } catch (Exception e) {
            Log.d(TAG, "Error occurred while disconnecting from ftp server.");
        }
    return false;
    }
    

    Now add the method to upload files to the FTP server.

    public boolean ftpUpload(String srcFilePath, String desFileName, String desDirectory, Context context) {
        boolean status = false;
        try {
            FileInputStream srcFileStream = new FileInputStream(srcFilePath);
            // change working directory to the destination directory
            // if (ftpChangeDirectory(desDirectory)) {
                status = mFTPClient.storeFile(desFileName, srcFileStream);
            // }
            srcFileStream.close();
            return status;
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "upload failed: " + e);
        }
    return status;
    }
    

    connection to your application in Android Studio to an FTP server?

    [tutorial from code] [3]

    How to start FTP on Android

        
    answered by 01.01.2018 / 04:33
    source