Uploading a file to a FTP server from android phone?

前端 未结 3 928
终归单人心
终归单人心 2020-12-28 09:18

Following is the code that\'s suppose to create a text document and upload it to my FTP server. For some reason it doesn\'t seem to work. I used to the libraries provided at

3条回答
  •  孤城傲影
    2020-12-28 09:54

    Here is the code block :

    private class UploadFile extends AsyncTask {
    
        @Override
        protected Boolean doInBackground(String... params) {
            FTPClient client = new FTPClient();
            try {
                client.connect(params[1], PORT);
                client.login(params[2], params[3]);
                client.setFileType(FTP.BINARY_FILE_TYPE, FTP.BINARY_FILE_TYPE);
                return client.storeFile(filename, new FileInputStream(new File(
                        params[0])));
    
            } catch (Exception e) {
                Log.d("FTP", e.toString());
                return false;
            }
        }
    
        @Override
        protected void onPostExecute(Boolean sucess) {
            if (sucess)
                Toast.makeText(activity, "File Sent", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(activity, "Error", Toast.LENGTH_LONG).show();
        }
    
    }
    

    Please get complete working project for uploading files to FTP server from below drive.

    File uploading to FTP is used PORT 21, required parameter to upload file on FTP..

    host name username password

    https://drive.google.com/file/d/0B80LBJs3JkaDYUNfZ3pDSkVJUDA/edit

提交回复
热议问题