1 Reply Latest reply: Aug 16, 2012 6:19 PM by EJP RSS

    How to  return ftp connection object EJB Session bean to Client

    956146
      hi all,


      EJB Session bean code-server code
      ---------------------------------

      public final FTPClient getDetails(String serverip , String userName , String password) throws RemoteException
      {
      FTPClient ftp = new FTPClient();

      ftp.connect(ftpHost.toString().trim());
                          
                          reply = ftp.getReplyCode();
                          
                          System.out.println("reply code is ==="+reply);
                          
                          // ftp.enterLocalPassiveMode();
           ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
           
                          if(!FTPReply.isPositiveCompletion(reply))
                          {
                               try
                               {
                                    ftp.disconnect();
                               }
                               catch (Exception e)
                               {
                                    e.printStackTrace();
                                    //System.err.println("Unable to disconnect from FTP server after server refused connection. "+e.toString());
                               }
                               throw new Exception ("FTP server refused connection.");
                          }
                          System.out.println("Connected to " + ftpHost + ". "+ftp.getReplyString());

                          if (ftp.login(ftpUserName.toString().trim(), ftpPassword.toString().trim()))
                          {
                               logflag=false;
                               //return false;
                               System.out.println("if part ftp connected..........");
                          }else
                          {
                               //return false;
                               System.out.println("Else part ftp connected..........");
                               logflag=true;
                          }


      return ftp;
      }

      Client program code
      -------------------


      Welcomehome home = (Welcomehome) PortableRemoteObject.narrow (ref, Welcomehome.class);
                     
                     Welcome wel = (Welcome)home.create( );
                     System.out.println("wel obj is "+wel);
                     System.out.println(wel.Welcome());
                     
                FTPClient ftp=(FTPClient) wel.getDetails("xxx","xxxx","xxxxx");
                     

      if(ftp.isConnected())
                     {
                          System.out.println("ftp connected in client");
                     }else
                     {
                          System.out.println("ftp not connected in client");
                     }


      1. client ftp objects is not connected.
      2.how to return server program FTPclient object to Client program ftpclient.


      kindly tell me how to return server program ftpclient objects to client program FTP object refernce.