Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting FTP active/passive mode with Java URLConnection

Tags:

java

ftp

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?

like image 899
Demiurg Avatar asked Jan 23 '23 13:01

Demiurg


1 Answers

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

like image 60
BalusC Avatar answered Jan 25 '23 23:01

BalusC