Apache Commons Net Ftp throws error: Invalid server reply (MLST): '250 on Android only on Samsung s7

Apache Commons Net Ftp throws error: Invalid server reply (MLST): '250 on Android only on Samsung s7

当我的应用程序尝试从 Ftp 服务器(使用 DietPi 的 Pi 零 W 上的 运行 下载文件时,它会抛出上述错误,但是当我尝试使用其他 phones(Xiaomi Redmi 4x with android 6.0 and Samsung Galaxy J5 运行 on android 7.0) 不会出现错误,仅在 Samsung galaxy s7 运行 android 7.0。此外,上传仍然可以从同一个 phone

Invalid server reply (MLST): '250-modify=20180603012615;perm=adfrw;size=3679098;type=file;unique=801U4A;UNIX.group=0;UNIX.mode=0777;UNIX.owner=0; /C-jegyzet.pdf'

以及引发错误的 class:

private class DownloadFileAsync extends AsyncTask<String, Long, Boolean>
    {
        ProgressBar downloadProgressbar;
        TextView titleTextView;
        TextView nameTextView;
        TextView percentageTextView;
        TextView completedTextView;
        CardView downloadCardView;

        boolean isFirstCall = true;
        String name;
        Long fileLength;
        String errorMessage = Constants.ErrorCodes.NO_ERROR_CODE;

        int progress;
        @Override
        protected Boolean doInBackground(String... strings)
        {
            int port = 21;
            FTPClient client = new FTPClient();
            try
            {
                client.connect(server, port);
                client.login(username, password);
                client.enterLocalPassiveMode();
                client.setFileType(FTPClient.BINARY_FILE_TYPE);
                client.setBufferSize(1);
                File fileToWrite = new File(strings[2] + "/" + strings[1]);
                name = strings[1];
                OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(fileToWrite));
                fileLength = client.mlistFile(strings[0]).getSize();
                client.setCopyStreamListener(new CopyStreamListener() {
                    @Override
                    public void bytesTransferred(CopyStreamEvent copyStreamEvent)
                    {

                    }

                    @Override
                    public void bytesTransferred(long l, int i, long l1)
                    {
                        progress += i;
                        if(progress > 50000)
                        {
                            progress = 0;
                            publishProgress(l, l1);
                        }


                    }
                });
                boolean isSuccessful = client.retrieveFile(strings[0], outputStream);
                client.logout();
                outputStream.close();
                return isSuccessful;



            } catch (IOException e) {
                errorMessage = e.getMessage();
                Log.d("ftperror", errorMessage);
                return false;
            }


        }

        @Override
        protected void onProgressUpdate(Long... values)
        {
            //int percentage = Math.round((float)(values[0] / fileLength) * 100);
            float c = (((float)values[0]/(float)fileLength)*100);
            int percentage = Math.round(c);
            if(isFirstCall)
            {
                isFirstCall = false;
                downloadCardView = ((Activity) context).findViewById(R.id.downloadingCardView);
                downloadProgressbar = ((Activity) context).findViewById(R.id.downloadingProgressBar);
                titleTextView = ((Activity) context).findViewById(R.id.downloadingTitleTextView);
                nameTextView = ((Activity) context).findViewById(R.id.donwloadingNameTextView);
                percentageTextView = ((Activity) context).findViewById(R.id.downloadingPercentageTextView);
                completedTextView = ((Activity) context).findViewById(R.id.downloadingCompletedTextView);

                downloadCardView.setVisibility(View.VISIBLE);
                titleTextView.setText(R.string.file_handler_downloading);
                nameTextView.setText(name);
                downloadProgressbar.setProgress(0);


            }
            downloadProgressbar.setProgress(percentage);
            percentageTextView.setText(percentage + "%");
            completedTextView.setText(android.text.format.Formatter.formatShortFileSize(context, values[0]) + "/" + android.text.format.Formatter.formatShortFileSize(context, fileLength));



        }

        @Override
        protected void onPostExecute(Boolean aBoolean)
        {
            if(!isFirstCall)
            {
                downloadCardView.setVisibility(View.GONE);
            }

            if (aBoolean)
            {
                Toast.makeText(context, R.string.file_handler_download_success, Toast.LENGTH_LONG).show();
            }
            else
            {
                Toast.makeText(context, R.string.file_handler_download_failure, Toast.LENGTH_LONG).show();
                if (!errorMessage.equals(Constants.ErrorCodes.NO_ERROR_CODE))
                {
                    DisplayFilesActivity displayFilesActivity = (DisplayFilesActivity)context;
                    displayFilesActivity.showError(errorMessage);
                }

            }

        }
    }

我想通了。问题不在于检索文件,而实际上在于 mlist 方法。原来我的 ftp 服务器实际上并不支持该命令。使用带有文件的列表作为参数具有相同的效果,我的代码适用于