Java FTP客户端无法将文件上传到服务器

时间:2019-07-14 19:45:09

标签: java ftp ftp-client apache-commons-net

我有基于apache-commons-net和Java 8的ftp客户端。本地操作系统Mac OS和Microsoft FTP服务。我可以下载文件,但是不能将文件上传到服务器550 Access is denied。但是我可以使用Windows资源管理器,Mac Finder和另一个FTP客户端(如FileZilla)进行上传。

我尝试过:设置storeFile()appendFile()-不起作用。 设置enterLocalPassiveMode()-不起作用。 设置enterRemotePassiveMode()-解析550代码,但文件未上传。

    void open() throws IOException {

        ftp = new FTPClient();

        ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

        ftp.connect(server, port);

        ftp.enterLocalPassiveMode();

        int reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            throw  new IOException("Exception in conneting to FTP Server");
        }

        ftp.login(user, password);

        ftp.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);

        ftp.enterRemotePassiveMode();

    }


    void downloadFile(String source, String destination) throws IOException{
        FileOutputStream out = new FileOutputStream(destination);
        ftp.retrieveFile(source, out);
    }

    void putFileToPath(File file, String path) throws IOException {

        if(ftp.storeFile(path, new FileInputStream(file))){
            System.out.println("file was upload");
        } else {
            System.out.println("file was not upload");
        }

    // or appendFile()

        if(ftp.appendFile(path, new FileInputStream(file))){
            System.out.println("file was upload");
        } else {
            System.out.println("file was not upload");
        }

    }

我尝试过:设置storeFile()appendFile()-不起作用。 设置enterLocalPassiveMode()-不起作用。 设置enterRemotePassiveMode()-解析550代码,但文件未上传。

0 个答案:

没有答案
相关问题