File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Is FTPClient optimized to reuse open connections? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Is FTPClient optimized to reuse open connections?" Watch "Is FTPClient optimized to reuse open connections?" New topic
Author

Is FTPClient optimized to reuse open connections?

Talib Jockey
Greenhorn

Joined: Aug 06, 2003
Posts: 22
I am using org.apache.commons.net.ftp.FTPClient class to connect to a remote server for FTP.

My doubt is that if I connect to the FTP Server using ftp.connect(), where ftp is a object of class FTPClient, I dont explicitly call ftp.disconnect() and again try connecting to the FTP Server through ftp.connect(), will it reuse the connection if it has not timedout?

The catch is that I create a new FTPClient object each time I call connect(), somethin like this..

FTPClient ftp = null;
ftp = new FTPClient();
ftp.connect();
ftp = new FTPClient();
ftp.connect();

Will it physically connect each time, or FTPClient(It uses Socket to connect) is optimized to reuse an exisitng open connection, inspite of the fact that I am creating a new object of FTPClient() each time?


SCJP 1.4 - 97%<br />SCWCD 1.4 - In Progress
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

If you use it's default configuration, FTPClient will use this class to create your connection:
DefaultSocketFactory.java.

It just uses java's standard java.net classes to open a connection. No caching or reuse involved.

Regards, Jan

(edit: I said cashing in stead of caching)
[ March 03, 2007: Message edited by: Jan Cumps ]

OCUP UML fundamental and ITIL foundation
youtube channel
Talib Jockey
Greenhorn

Joined: Aug 06, 2003
Posts: 22
Thanks Jan!

So each time a new Socket object is created i.e. it will physically connect to the Server (I connect in the passive mode). Is that right?
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

Yes.

Regards, Jan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is FTPClient optimized to reuse open connections?