小编Igo*_*gor的帖子

Apache Commons FTP问题

我想用Apache Commons Net实现一个FTP客户端,仅用于上传数据.连接和登录FTP服务器工作正常.但上传不能正常工作.文件与原件有点大.并且文件已损坏.我尝试了一个图像,一个视频和一个文本文件.只有文本文件没问题.

现在我看到调试时

boolean tmp=client.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
Run Code Online (Sandbox Code Playgroud)

给了我false.所以它无法设置.为什么?(也许这不是问题?)

这是我的其余代码

client=new FTPClient();

    try {           
        int reply;
        client.connect(url, port);
        reply = client.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply))
        {
            client.disconnect();
            System.err.println("FTP server refused connection.");
            System.exit(1);
        }


        client.login(user, pw);
        boolean xxx=client.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
        client.setControlKeepAliveTimeout(300);
        client.enterLocalPassiveMode();

if (client.isConnected())
    {
    try {
        File file=new File(<FILE>);
        FileInputStream inputStream = new FileInputStream(file);
        OutputStream outputStream = client.storeFileStream(file.getName());

          byte[] buffer = new byte[4096];
          int l;
       while((l = inputStream.read(buffer))!=-1)
               {
                outputStream.write(buffer, 0, l);
            }

          inputStream.close();
          outputStream.flush();
          outputStream.close();}
Run Code Online (Sandbox Code Playgroud)

java ftp apache-commons-net

5
推荐指数
1
解决办法
9786
查看次数

标签 统计

apache-commons-net ×1

ftp ×1

java ×1