URLConnection设置FTP主动

URLConnection设置FTP主动

本文介绍了使用Java URLConnection设置FTP主动/被动模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用URLConnection类时可以设置FTP被动或主动模式吗?我找不到任何文档,但这是一个基本功能,很难相信它没有实现。



如果不是,我还有什么其他选项在标准的Java?

解决方案

为了让FTP充分发挥作用,你真的需要退回到低级编程与。 URLConnection 和配合根本无法满足您的需求(不支持进入被动模式)。幸运的是,Apache Commons已经为提供了大量的工作。要实现您所需的内容,只需使用或

Is it possible to set FTP passive or active mode when working with URLConnection class? I cannot find any documentation on this, yet this is such a basic functionality that it's hard to believe it is not implemented.

If it's not, what other options do I have in standard Java?

解决方案

To get FTP full fledged to work, you'll really need to fall back to low-level programming with Sockets. The URLConnection and consorts simply doesn't suit your needs (no support to enter into passive mode). Fortunately Apache Commons has already done a lot of work for you in flavor of Apache Commons Net FTPClient. To achieve what you need, just use FTPClient#enterLocalPassiveMode() or FTPClient#enterLocalActiveMode()

这篇关于使用Java URLConnection设置FTP主动/被动模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:55