Apache Commons FTP问题

伊戈尔:

我想用Apache Commons Net实现FTP客户端,仅用于上传数据。连接和登录到FTP服务器正常。但是上传无法正常进行。文件有点像原始文件。并且文件已损坏。我尝试了图像,视频和文本文件。仅文本文件可以。

现在我在调试时看到了

boolean tmp=client.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);

给我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();}
皇冠:

更改以下内容:

boolean xxx=client.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);

应该:

boolean xxx=client.setFileType(FTP.BINARY_FILE_TYPE);

您已经将FileTransferModes与FileTypes混淆了。

可用的文件类型为:

可用的FileTransferModes是:

我想如果apache为这些常量类型引入了枚举,那么可以避免这种问题,但是该库对于java-5之前的运行时将不可用。
我不知道Java 1.4兼容性到底有多少问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Apache Commons Java FTP上传问题

org.apache.commons.net.ftp.FTPClient listFiles()出现问题

使用org.apache.commons.net.ftp.FTPClient保护FTP

Apache Commons Net FTP正在上传损坏的文件

如何导入org.apache.commons.net.ftp.FTPClient

在Apache Commons-net中使用FTP代理

在Apache Commons Net中启用FTP协议登录

使用Apache Commons Net下载后FTP文件损坏

org.apache.commons.net.ftp使用其他端口

Java Apache Commons库源许可证问题

JSP中导入org.apache.commons的问题

Apache Commons CLI(选项)

Apache Commons FTPClient挂起

Google Guava与Apache Commons

Apache Commons Unzip方法?

Apache-Commons Commons-Functor的状态

Java的FTP org.apache.commons.net.MalformedServerReplyException:截断服务器响应: '220'

Apache commons NET FTP 检索在文件读取后不起作用

无法使用Apache Commons FTPClient访问FTP服务器上的子文件夹

使用Apache Commons和Java FTP下载后,Word文档将无法打开

org.apache.commons.net.ftp中FTPClient类中的enterLocal ...()和enterRemote ...()方法之间的区别

Apache Commons FTP被动模式,如何设置远程监听端口(数据流)

在 Java 上下载 FTP 文件夹(使用 FTPClient Apache Commons Net 3.6 API)

带有Apache Commons ftp的gradle错误“ ZipException:重复条目:org / apache / ftpserver / ftplet / Authentication.class”

Apache Commons Configuration:ClassNotFoundException:org.apache.commons.beanutils.DynaBean

java.lang.NoClassDefFoundError:无法解决以下问题:Lorg / apache / commons / logging / LogFactory

在春季用apache-commons-fileupload上传文件时出现问题

尝试使用apache commons httpclient类登录到https安全的问题

Apache Commons Logging的运行时发现算法有什么问题