【问题标题】:Apache Commons Net Ftp throws error: Invalid server reply (MLST): '250 on Android only on Samsung s7Apache Commons Net Ftp 抛出错误:无效的服务器回复(MLST):'250 on Android only on Samsung s7
【发布时间】:2018-06-03 08:04:55
【问题描述】:

当我的应用程序尝试从 Ftp 服务器下载文件(使用 DietPi 在 Pi 零 W 上运行)时,它会引发上述错误,但是当我尝试使用其他手机(运行 android 6.0 和三星 Galaxy J5 的小米红米 4x)时在 android 7.0 上)不会发生错误,仅在运行 android 7.0 的三星 Galaxy s7 上发生。此外,仍然可以从同一部手机上传

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'

以及引发错误的类:

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);
                }

            }

        }
    }

【问题讨论】:

  • 你无法检查这些函数的返回值。
  • 您无处使用该功能“等待最后一个挂起的操作完成”。抱歉忘记了真名。
  • 实际上,在 onPostExecute 中,应用程序会告诉您操作是否失败,就像在当前情况下一样。正如我告诉你的那样,除了三星 Galaxy s7 之外,该课程都有效

标签: java android ftp apache-commons-net samsung-galaxy


【解决方案1】:

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

【讨论】:

  • 那你的问题描述一定是错误的。如果您连接到同一台服务器,它如何在某些设备上工作?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-13
  • 1970-01-01
  • 2021-11-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多