This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply 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: 2343

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
ITIL foundation
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: 2343

Yes.

Regards, Jan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is FTPClient optimized to reuse open connections?
 
Similar Threads
FTP Client
I/O stream handling by FTPClient
FTP Client MultiThread
Problem FTP the files using java
FTPClient : is not working