How couldn't I download a .txt file from FTP Folder but can list the files and upload?

122 Views Asked by At

I have a weird issue that I can connect , send files to my FTP Folder or list the files there but I couldn't download any.

Dependency :

  • Apache-commons net

FTP

username : test
password :      *(no password)*

Permission:

the download folder is writable, because i'm programming POI, it generates/writes the files within the same folder. I don't quite believe that this is my android permission issue (permission for writing has also been set up manually via setting)

Code: (function is called within a background thread, it runs)

public static FTPFile[] downloadFiles(String host, String username, String password, int port, String localFilePath, String remoteFilePath) throws IOException {          
        try {
            mFTPClientForDownloadingFiles = new FTPClient();
            // connecting to the host
            mFTPClientForDownloadingFiles.connect(host, port);
            // now check the reply code, if positive mean connection success
            if (FTPReply.isPositiveCompletion(mFTPClientForDownloadingFiles.getReplyCode())) {
                // login using username & password
                boolean status = mFTPClientForDownloadingFiles.login(username, password);
                System.out.println("status koneksi download file FTP" + status);
                mFTPClientForDownloadingFiles.setFileType(FTP.BINARY_FILE_TYPE);
                mFTPClientForDownloadingFiles.enterLocalPassiveMode();       
           
                try (
                        FileOutputStream fos = new FileOutputStream(new File(localFilePath.trim()))

                ) {
               boolean isDownloading=  mFTPClientForDownloadingFiles.retrieveFile(remoteFilePath, fos);

                  System.out.println("IS DONWLOADING ? "+isDownloading);
                } catch (IOException e) {
                    e.printStackTrace();
                }


            }
        } catch (Exception e) {
            Log.d("FTP_DOWNLOADFILES", "Error: could not connect to host " + e.getCause());
            Log.d("FTP_DOWNLOADFILES", "Error: could not connect to host " + e);
            Log.d("FTP_DOWNLOADFILES", "Error: could not connect to host " + host);
        }

        return files;
    }

Calls

     // Try downloading
                          MainAppUtility.downloadFiles(editTextIP.getText().toString(), String.valueOf(editTextUsername.getText()), String.valueOf(editTextPassword.getText()), 21,"ambil.txt","/storage/emulated/0/Download/hasil.txt");

or

     // Try downloading
                          MainAppUtility.downloadFiles(editTextIP.getText().toString(), String.valueOf(editTextUsername.getText()), String.valueOf(editTextPassword.getText()), 21,"/ambil.txt","/storage/emulated/0/Download/hasil.txt");

Android studio says that

I/System.out: status koneksi download file FTPtrue W/System.err: java.io.FileNotFoundException: /ambil.txt (Read-only file system) W/System.err: at java.io.FileOutputStream.open0(Native Method) W/System.err: at java.io.FileOutputStream.open(FileOutputStream.java:287) W/System.err: at java.io.FileOutputStream.(FileOutputStream.java:223) W/System.err: at java.io.FileOutputStream.(FileOutputStream.java:171) W/System.err: at com.koding.tablistview.MainAppUtility.downloadFiles(MainAppUtility.java:181)

It is weird because I'm sure that my FTP server is given permission already

enter image description here

I'm aware that my FileZilla server says:

enter image description here

0

There are 0 best solutions below