Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data Port Issue

 
Tony Moses
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have written a BTB tool to transfer files from a client to a server application over FTP. The server application is written in Java and we used the JFTPD code as a baseline. In unit testing on a Windows box the code works perfectly. When we moved the server application to pilot on a unix box (Solaris) the application fails. The client can successfully connect over the control port on a non-standard port (not 21). When the client tries to execute a put it fails with the following error on the server application: Connection Refused. It is occuring on the following line of code: Socket dataSocket = new Socket(dataHost, dataPort) where dataHost is a String parameter and dataPort is an Int. The dataPort is being set as the control port + 1.

The JFTPD code that we used as our starting point has a stubbed out method to handle the PASV command, however there is no code to do anything with the command. We seem to think that PASV will resolve our issue of the data port connection being refused.

Are we on the right or are there any other suggestions?

Thanks.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,

PASV will absolutely fix the problem if the root cause of the problem is a firewall of some kind which is not letting the data connection through. This is a pretty common issue with FTP so it's quite likely to be the case.
 
Tony Moses
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like the socket object does not offer the ability to set passive mode. Is there a replacement object to the Socket object that would allow us to set passive mode?

Thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the commons/net libraries from the Jakarta group.
http://commons.apache.org/net/apidocs/org/apache/commons/net/ftp/FTPClient.html#enterLocalPassiveMode()

Even if you don't want to use them, a peek at their source code might get you going in the right direction.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a little complicated. PASV is not a property of a socket. It's an FTP command, and what it does it change the responsibilities of the client and server with respect to initiating that second connection, the data connection. In "active" mode, the client opens a connection for listening and tells the server "connect to this port, and send the data." Firewalls will block that incoming connection; that's why active mode doesn't work for you.

In passive mode, however, it's up to the server to say "here's a port, connect to this and I'll send the data though the connection." The client firewall will generally be fine with that.

You'll need to look at the RFC here if you're going to implement the PASV command. It really shouldn't be too hard.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic