I want to upload to FTP server using Apache commons library, but I can't.

Asked 2 years ago, Updated 2 years ago, 48 views

I would like to create a program on Android that uploads text files to the FTP server using Apache commonsnet, but the Reply Code 500 was returned and I cannot do so.
Here's the program (it's actually in AsyncTask):

private class FTP extensions ContextWrapper{

    public FTP (Context context) {
        super(context);
    }

    private String putData{
        int reply = 0;
        boolean isLogin=false;
        FTPClient FTPCl = new FTPClient();

        try{
            FTPCl.setConnectTimeout (5000);
            FTPCl.connect("****.****.jp", 21);
            reply = FTPCl.getReplyCode();
            if(!FTPReply.isPositiveCompletion(reply)){
                through new Exception("Connect Status:" + String.valueOf(reply));
            }

            if(!FTPCl.login(<User ID>,<Password>)){
                through new Exception ("Invalid user/password");
            }
            isLogin = true;

            FTPCl.enterLocalActiveMode();

            FTPCl.setDataTimeout (15000);
            FTPCl.setSoTimeout (15000);
            FileInputStream fileInputStream=this.openFileInput("hoge.txt");

            FTPCl.storeFile("files/", fileInputStream);
            reply = FTPCl.getReplyCode();
            if(!FTPReply.isPositiveCompletion(reply)){
                through new Exception("Send Status:" + String.valueOf(reply));
            }
            fileInputStream.close();


            FTPCl.logout();
            isLogin=false;

            FTPCl.disconnect();
        } catch(Exceptione){
            return.getMessage();
        } US>finally
            if(isLogin){
                try{
                    FTPCl.logout();
                } catch(IOExceptione){

                }
            }
            if(FTPCl.isConnected()){
                try{
                    FTPCl.disconnect();
                } catch(IOExceptione){

                }
            }
            FTPCl = null;
        }
        return null;
    }

}

android java

2022-09-30 19:56

1 Answers

According to the document,
The first argument for FTPCl.storeFile appears to be a filename, not a directory.
storeFile(java.lang.String, java.io.InputStream)

A method is provided to change the Working directory.
changeWorkingDirectory(java.lang.String)

This answer may be helpful.


2022-09-30 19:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.