Setting FTP active/passive mode with Java URLConne

2019-01-28 04:35发布

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?

标签: java ftp
2条回答
聊天终结者
2楼-- · 2019-01-28 05:19

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()

查看更多
来,给爷笑一个
3楼-- · 2019-01-28 05:34

Today, we capture TCP/IP packet and confirm that the Android/JAVA/URLConnection still use PORT(Active mode) for FTP.

If the server don't support active mode or the network don't support active mode, the URLConnection will failed.

查看更多
登录 后发表回答