-
URGENT: FTP Client / Server using RMI
Hi All.
I have been given a task where I have been asked to implement a Java RMI version of an SFTP (Simple File Transfer Protocol) Client / Server. It must use the following commands:
list - list files in current directory
cd - change directory
get filename - copy file from server to client
put - upload file from client to server
bye - close connection
In essence, a FTPServer Factory has to be created which i'm guessing would use the rmi registry to handle requests between the client and server.
I have the RMI part figured out, just trying to get the FTP part working...
I decided to use the Java Library from JScape Inet Factory and all classes compile, the Ftp Server is running and waits for a connection on port 1099 the designated default RMI port.
When the Client starts up it asks user to confirm localhost name and then asks user for username and password, these are hardcoded as "user" and "pass" respectively.
The client then begins to log in, the client finds the RMI name through the registry and then trys to log into the FTP server, but everytime it tries to do this it times out as it cannot see the FTP Server. Any ideas??
I have attached code for FTPServer, the Implementation and the Client...any help would be appreciated
Thanks
RMI FTP SERVER
Code:
package server;
import java.net.*;
import java.net.UnknownHostException;
import java.io.*;
import java.util.*;
import java.lang.Thread;
import java.rmi.*;
import java.rmi.Remote;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.*;
import com.jscape.inet.ftp.*;
import com.jscape.inet.ftp.FtpException;
import server.*;
public class RmiFtpServer {
//static String hostName = "localhost";
private static String hostName;
private static int hostPort = 1099;
static RmiFtpImpl rmi;
public static void main(String[] args) throws RemoteException, FtpException, UnknownHostException {
String host;
String port;
String badhost;
String error;
//System.setSecurityManager(new RMISecurityManager());
try {
InetAddress addr = InetAddress.getLocalHost();
// Get IP Address
byte[] ipaAddr = addr.getAddress();
// Get Host Name
String hostName = addr.getHostName();
RmiFtpImpl rmi = new RmiFtpImpl("RmiFtpServer");
System.out.println("RmiFtpServer object created...");
System.out.println("Registering FTP Server with RMI Naming service...");
String serverObjectName = "rmi://localhost/RmiFtpServer";
Naming.rebind(serverObjectName, rmi);
System.out.println("RmiFtpServer bound in RMI registry");
host = "Bindings Finished. FTP Server hostname is: " + hostName;
System.out.println(host);
port = "Waiting for FTP Client requests on port "+ hostPort +" ...";
System.out.println(port);
}
catch (UnknownHostException uhe) {
badhost = "The host computer name you have specified, "+ hostName +" does not match your real computer name.";
System.out.println(badhost);
//System.exit(1);
}
catch (RemoteException re) {
error = "Error starting service :"+re;
System.out.println(error);
//System.exit(1);
}
catch (MalformedURLException url) {
System.out.println("RmiFtpServer URL Error: " + url.getMessage());
}
}
}
RMI IMPLEMENTATION
Code:
package server;
import java.io.*;import java.lang.*;
import java.net.*;
import java.net.InetAddress.*;
import java.net.UnknownHostException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.util.*;
import com.jscape.inet.ftp.*;
import server.*;
public class RmiFtpImpl extends UnicastRemoteObject implements RmiFtp
{ // begin class
private static String hostName;
private String host, user, password;
private String name;
private int port;
String ftpEx;
Login log;
public RmiFtpImpl(String s) throws RemoteException
{ // begin rmiftpimpl
super();
name = s;
} // end rmiftpimpl
public boolean doLogin()
throws RemoteException, UnknownHostException { // begin do login
System.out.println ("doLogin() method begins here...");
//log = new Login(host, user, password, port);
System.out.println ("validation begins...");
System.out.println ("validation should finish here...");
try { // begin try
System.out.println ("Attempt to create FTP object...");
InetAddress addr = InetAddress.getLocalHost();
// Get IP Address
byte[] ipaAddr = addr.getAddress();
// Get Host Name
String hostName = addr.getHostName();
host = hostName;
user = "user";
password = "pass";
Ftp ftpconn = new Ftp(host,user,password);
System.out.println ("FTP object created...");
System.out.println(ftpconn);
//ftpconn.addFtpListener(this);
ftpconn.connect();
System.out.println("connection created...");
//String results = ftpconn.getDirListingAsString();
//System.out.println(results);
//ftpconn.disconnect();
return true;
} // end try
catch (FtpException ex) { // begin catch
ftpEx = "FTP Exception: " + ex.getMessage();
System.out.println(ftpEx);
return false;
} // end catch
catch (UnknownHostException uhe) {
System.out.println("Host Exception Error: " + uhe.getMessage());
return false;
}
}
}
RMI FTP SERVER
Code:
/*
package client;
/**
*
* @author
*/
import com.jscape.inet.ftp.*;
import java.io.*;
import java.net.*;
import java.net.MalformedURLException;
import java.rmi.*;
import java.rmi.Remote;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.util.Enumeration;
import server.RmiFtp;
public class RmiFtpClient extends FtpAdapter implements FtpListener {
public static String servHost;
private static String hostName;
public static void main(String[] args) throws RemoteException {
if (System.getSecurityManager() == null)
{
System.setSecurityManager(new RMISecurityManager());
}
servHost = "localhost";
if (args.length < 1) {
System.out.println("Usage: java RmiFtpClient <rmihost>");
}
else {
servHost = args[0];
}
new RmiFtpClient();
}
public RmiFtpClient() {
String host;
String user;
String password;
//int port = 1099;
RmiFtp rmi = null;
try {
InetAddress addr = InetAddress.getLocalHost();
// Get IP Address
//byte[] ipaAddr = addr.getAddress();
// Get Host Name
String hostName = addr.getHostName();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Ftp hostname (e.g. ftp.yourhost.com): " + hostName);
host = reader.readLine();
System.out.print("Enter username (e.g. anonymous): ");
user = reader.readLine();
System.out.print("Enter password (e.g. password): ");
password = reader.readLine();
rmi = (RmiFtp)Naming.lookup("rmi://localhost/RmiFtpServer");
System.out.println ("Naming OK");
System.out.println("Logging in to FTP Server...");
rmi.doLogin();
System.out.println("did it work?");
}
catch(RemoteException re) {
System.out.println("FTP RemoteException Error: " + re.getMessage());
}
catch(IOException io) {
System.out.println("FTP IO Error: " + io.getMessage());
}
catch(NotBoundException e) {
e.printStackTrace();
}
}
}
-
i have already appreciated your work. Mr iwinn can you send me the class or file RmiFtp because it doesn't exist here. thanks to you.
my email is: Removed By Mod
Last edited by Hack; 10-23-2008 at 01:13 PM.
Reason: Removed EMail Address
-
@mohammedbaaziz: I have edited your post and removed your email address.
You should never post your email address in an open post on an open forum. Mail spam bots can pick that up and before you know it, your mailbox is full of junk mail. If you wish to share your email address with other forum members, please do so via our PM system.
In addition, we prefer all answers to questions be publically posted rather than sent via EMail or PM. That way, everyone with a similar problem can benefit.
Thanks.
Similar Threads
-
By rperez in forum Database
Replies: 5
Last Post: 01-02-2009, 04:14 PM
-
Replies: 0
Last Post: 06-15-2005, 07:31 PM
-
By Patrick Lauber in forum Open Source
Replies: 0
Last Post: 03-07-2001, 10:52 AM
-
By Sreedhar Kaluva in forum Database
Replies: 0
Last Post: 02-13-2001, 08:15 PM
-
Replies: 2
Last Post: 04-20-2000, 08:12 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|