wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes 500 Illegal PORT Command using Apache commons net FTP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "500 Illegal PORT Command using Apache commons net FTP" Watch "500 Illegal PORT Command using Apache commons net FTP" New topic
Author

500 Illegal PORT Command using Apache commons net FTP

Sridhar Gollapalli
Greenhorn

Joined: Sep 14, 2006
Posts: 4
Hi All,
<br>
Please help me
<br><br><p>
My requirement is to transfer file from server to server transfer using ftp, since files are located in one server and need to transfer to another server. I am using Apache commons net ftp to transfer files. My application resides in another third server. All the 3 servers(my application, files located server, destination location server) are linux boxes and using vsftp 2.0.1 version for ftp.
<br><p>
Since I am from j2ee background i have less idea on ftp.
I need to establish the client/server(2 servers) communication between two servers to transfer file, since my application resides in third server. I could connect to two servers and change to working directory. Problem is I am making one of the server (files located server) to listen the client (destination location server) by making passive command.

<br><br>
Below is output of small program
<br><br>


Connecting FTP1 55
<br>
220 (vsFTPd 2.0.1)
<br><br>
USER oracle9i
<br><br>
331 Please specify the password.
<br><br>
PASS oracle9i
<br><br>
230 Login successful.
<br><br>
Connecting FTP2 43
220 (vsFTPd 2.0.1)
<br><br>

USER oracle9i
<br><br>

331 Please specify the password.
<br><br>

PASS oracle9i
<br><br>

230 Login successful.
<br><br>

CWD /opt/oracle/cp360data/dev/fgr_manfacture
<br><br>

250 Directory successfully changed.
<br><br>

replyCode 1 : 250
CWD /cp360data/dev/rxpfs/SPAN/GISFEntity_TXT4/
<br><br>

250 Directory successfully changed.
<br><br>

replyCode 2 : 250<br>
PASV
<br><br>

227 Entering Passive Mode (192,168,21,43,52,77)
<br><br>

FtpClient2 is in Passive mode<br>
FtpClient2 Host : /192.168.aa.bb<br>
FtpClient2 Port : 13389<br>
FtpClient1 is entering RemoteActive Port : <br>
PORT 192,168,21,43,52,77<br>
<br><br>

500 Illegal PORT command.
<br><br>

FtpClient1 is entering RemoteActive : <br>
FtpClient1 is NOT in Active mode<br>
FtpClient1 Remote verification : true<br>
FtpClient2 Remote verification : true<br>
Couldn't initiate transfer. Check that filenames are valid.<br>
250<br>
Disconnecting FTP1<br>
Disconnecting FTP2<br>
Finished FTP

<br><br>
Below code
<br>
public void ftping(){<br>
FTPClient ftpClient1 = new FTPClient();<br>
FTPClient ftpClient2 = new FTPClient();<br>
ProtocolCommandListener listener;<br>
try{<br>
listener = new PrintCommandListener();<br>
ftpClient1.addProtocolCommandListener<br>(listener);<br>
ftpClient2.addProtocolCommandListener(listener);<br>

System.out.println("Connecting FTP1 55");<br>
ftpClient1.connect("192.168.aa.bb");<br>
ftpClient1.login("user", "pwd");<br>
if (!FTPReply.isPositiveCompletion(ftpClient1.getReplyCode())) {<br>
String errMsg = "User : oracle9i could not connect. FTP server refused connection.";<br>
System.out.println(errMsg);<br>
}<br>

System.out.println("Connecting FTP2 43");<br>
ftpClient2.connect("192.168.cc.dd");<br>
ftpClient2.login("user1", "pwd");<br>
if (!FTPReply.isPositiveCompletion(ftpClient2.getReplyCode())) {<br>
String errMsg = "User : oracle9i could not connect. FTP server refused connection.";<br>
System.out.println(errMsg);<br>
}<br>


String fromPath = "/opt/oracle/cp360data/dev/fgr_manfacture";<br>
String toPath = "/cp360data/dev/rxpfs/SPAN/GISFEntity_TXT4/";<br>
//String filePath = "GISFEntity_TXT5";<br>
String file1 = "GISF_20070327-1432.XML";<br>
String file2 = "GISF_20070327-1432.XML";<br>



int replyCode = ftpClient1.cwd(fromPath);<br>
System.out.println("replyCode 1 : "+replyCode);<br>
if (!FTPReply.isPositiveCompletion(replyCode)) {<br>
String errMsg = "Could not change to directory : "
+ fromPath;<br>
System.out.println(errMsg);<br>
}<br>

int replyCode2 = ftpClient2.cwd(toPath);<br>
System.out.println("replyCode 2 : "+replyCode2);<br>
if (!FTPReply.isPositiveCompletion(replyCode2)) {<br>
String errMsg = "Could not change to directory : "
+ toPath;<br>
System.out.println(errMsg);<br>
}<br>

_main: <br>
try{<br>
boolean isPassive = ftpClient2.enterRemotePassiveMode();<br>
boolean isActive = false;<br>

if(isPassive){<br>
System.out.println("FtpClient2 is in Passive mode");<br>
System.out.println("FtpClient2 Host : "+ftpClient2.getPassiveHost());<br>
System.out.println("FtpClient2 Port : "+ftpClient2.getPassivePort());<br>
System.out.println("FtpClient1 is entering RemoteActive Port : ");<br>
isActive = ftpClient1.enterRemoteActiveMode(InetAddress.getByName(ftpClient2.getPassiveHost()), ftpClient2.getPassivePort());<br>
if(isActive)<br>
{<br>
System.out.println("FtpClient1 is in Active mode");<br>
}<br>
else<br>
{<br>
System.out.println("FtpClient1 is NOT in Active mode");<br>
}<br>
System.out.println(" FtpClient1 Remote verification : "+ftpClient1.isRemoteVerificationEnabled());<br>
System.out.println(" FtpClient2 Remote verification : "+ftpClient2.isRemoteVerificationEnabled());<br>
}<br>
else<br>
{<br>
System.out.println("FtpClient2 is NOT in Passive mode");<br>
}<br>

/*boolean remoteRet = ftpClient1.remoteRetrieve(file1);<br>
boolean remoteStore = ftpClient2.remoteStoreUnique(file2);<br>
ftpClient1.completePendingCommand();<br>
ftpClient2.completePendingCommand();<br>

System.out.println("FtpClient1 remote Retrive "+remoteRet);<br>
System.out.println("FtpClient2 remote Store "+remoteStore);*/<br>

if (ftpClient1.remoteRetrieve(file1) && ftpClient2.remoteStoreUnique(file2))
{<br>
System.out.println("File Transferring ...");<br>
//if(ftp1.remoteRetrieve(file1) && ftp2.remoteStore(file2)) {<br>
// We have to fetch the positive completion reply.<br>
ftpClient1.completePendingCommand();<br>
ftpClient2.completePendingCommand();<br>
}<br>
else<br>
{<br>
System.out.println("Couldn't initiate transfer. Check that filenames are valid.");<br>
break _main;<br>
}<br>
} catch(Exception e){<br>
<br>
}<br>






System.out.println(replyCode);<br>
System.out.println("Disconnecting FTP1");<br>
ftpClient1.disconnect();<br>
System.out.println("Disconnecting FTP2");<br>
ftpClient2.disconnect();<br>
System.out.println("Finished FTP");<br>



} catch(Exception e){<br>
System.out.println("Exception Occured");<br>
if (ftpClient1.isConnected())<br>
{<br>
try
{<br>
ftpClient1.disconnect();<br>
}<br>
catch (IOException f)<br>
{<br>
// do nothing<br>
}<br>
}<br>
if (ftpClient2.isConnected())<br>
{<br>
try<br>
{<br>
ftpClient2.disconnect();<br>
}<br>
catch (IOException f)<br>
{<br>
// do nothing<br>
}<br>
}<br>
System.out.println("Error : "+e);<br>
}<br>
}<br>

<br><br>
Please help me in setting configurations at vsftp side.
James Barwick
Greenhorn

Joined: Dec 20, 2011
Posts: 1
Ditto
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

That was really hard to read. We have a "Code" button on our message editor. It wraps tags around pre-formatted text to make it easier to read. Although omitting the escaped HTML would have helped, too.

The ILLEGAL PORT response usually indicates that the firewall of the FTP server needs to be adjusted.

FTP is not necessarily the optimal way of inter-server file transfer, however. If the source and destination servers are both in a secure sub-network, you can use NFS or even CIFS (Windows file sharing). Other options include scp, rsync, and even HTTP file upload.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
Consider Paul's rocket mass heater.
 
subject: 500 Illegal PORT Command using Apache commons net FTP
 
Similar Threads
FTPClient : is not working
Problem with InputStream using org.apache.commons.net
Problem FTP the files using java
Apache Common FTPClient
Problems uploading file to FTP