File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is FTPClient optimized to reuse open connections?

 
Talib Jockey
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jan Cumps
Bartender
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Talib Jockey
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.

Regards, Jan
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic