• Post Reply Bookmark Topic Watch Topic
  • New Topic

I/O stream handling by FTPClient

 
Talib Jockey
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using org.apache.commons.net.FTPClient instance to connect to a remote FTP Server.

If I do the following...

FTPClient ftp = null;
ftp = new FTPClient();
ftp.connect("host1");
ftp.login(...);
ftp.connect("host2");
ftp.login(...);

and then call

ftp.storeFile(...)

where will the file get stored .. host1 or host 2(assume here that I have logged in)?

Can someone explain how does FTPClient handle I/O streams when multiple connections are opened from a single FTPClient instance.

Does the previous connection become inactive after I make a new connection with the same FTPClient instance?

Thanks!
 
Paul Clapham
Sheriff
Posts: 21875
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not try it yourself and see what happens?

My guess is that if you tell the client to connect to host2, it will connect to host2. And that subsequently if you tell it to send a file, it will send a file to host2. But that's just guessing based on how sensible people would design systems.
 
Jan Cumps
Bartender
Posts: 2614
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As seen in the source,

FTPClient Creates a socket to server 1,
and Connects.

Then it creates a socket to server 2, without closing the server 1 socket.
Although the first socket will become available for garbage collection, you have not properly cleaned it up. The api asks you to close the connection before connecting again (see later in the reply).

Then you write your file to server 2.

From the disconnect() api documentation:
Disconnects the socket connection. You should call this method after you've finished using the class instance and also before you call connect() again.



Regards, Jan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!