首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Apache Commons Net Ftp抛出错误:无效服务器回复(MLST):'250仅适用于三星s7上的安卓系统

Apache Commons Net Ftp抛出错误:无效服务器回复(MLST):'250仅适用于三星s7上的安卓系统
EN

Stack Overflow用户
提问于 2018-06-03 16:04:55
回答 1查看 371关注 0票数 -1

当我的应用程序尝试从Ftp服务器(运行在带DietPi的Pi zero W上)下载文件时,它会抛出上述错误,但当我尝试使用其他手机(安卓6.0的小米Redmi 4x和安卓7.0上运行的三星galaxy J5 )时,该错误不会发生,只有在运行安卓7.0的三星Galaxy s7上才会出现。同样,上传仍然可以在同一部手机上运行

代码语言:javascript
复制
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'

以及抛出错误的类:

代码语言:javascript
复制
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);
                }

            }

        }
    }

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-05 18:01:11

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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50664426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档