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.