Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.4k views
in Java FTP by (220 points)
Hi All,
I am new to edtftp. I have a fair amount of Java experience, and I am making a custom class, extending the FTPClient class shipped with the edtftpj software. Here are the relevant methods of my class:


public class FTPService extends FTPClient{
   static Logger log = Logger.getLogger(FTPService.class);
   FTPMessageCollector listener;
   
   /**
    * Default Constructor
    *
    */
   public FTPService(){
      log.debug("FTPService() created.");
      
   }

   /**
    * Sets up FTP client
    * @param host
    * @throws Exception
    */
   public void setup(String host) throws Exception{
        // Set up client    
        setRemoteHost(host);
        listener = new FTPMessageCollector();
        setMessageListener(listener);
   }
   
   /**
    * Connects to client
    * @param client
    * @throws Exception
    */
   public void connect(String client) throws Exception{
      log.info("Connecting to " + client);
      connect();
   }
   
   /**
    * Logs into remote system
    * @param user
    * @param pass
    * @throws Exception
    */
   public void loginInfo(String user, String pass) throws Exception{
      log.info("Logging in...");
      login(user, pass);
   }
    
   /**
    * Changes reemote directory to supplied directory
    * @param chdir
    * @throws IOException
    * @throws FTPException
    */
   public void changeDir(String chdir) throws IOException, FTPException{
      log.info("changing directory to "+ chdir);
      chdir(chdir);
   }
   
   /**
    * Set the type of file transfer, and the connection mode.
    * @param connectMode
    * @param setType
    */
   public void setParameter (String connectMode, String type) throws Exception{
        log.debug("Setting up transfers");
      FTPConnectMode mode;
      FTPTransferType transType;
      
      //What kind of connection is it?
        if(connectMode.equalsIgnoreCase("actv"))
           mode = FTPConnectMode.ACTIVE;
        else
           mode = FTPConnectMode.PASV;
        //now, set the connection mode based on what's passed into method.
        setConnectMode(mode);
        
        //What kind of transfer is it?
        if(type.equalsIgnoreCase("ascii"))
           transType = FTPTransferType.ASCII;
        else 
           transType = FTPTransferType.BINARY;
        //Set the transfer type based on what's passed into the method.
        setType(transType);      
   }
   
   /**
    * Puts the specified file referenced by the full path, on the remote server
    * with the same name.
    * @param filename
    * @param remoteName
    * @throws Exception
    */
   public void putFile(String filename, String remoteName) throws Exception{
        // copy file to server 
        log.info("Putting file: " + filename);
        put(filename, remoteName);      
   }
   
   public void getDir() throws Exception{
        // get directory and print it to console            

        log.debug("Directory after put");
        String[] files = dir(".", true);
        for (int i = 0; i < files.length; i++)
            log.debug(files[i]);
        
        //return files;
   }
   
   public void closeConnection() throws Exception{
        // Shut down client                
        log.info("Quitting client");
        quit();
   }
   
   public String getMessage(){
        String messages = listener.getLog();
        log.debug("Listener log:");
        log.debug(messages);
      return messages;
   }


I call the methods from another class, running on a timer. Here are the method calls:
service = new FTPService();
/*
* The next three lines initialize, connect and log into
* the ftp host.
*/
service.setup(recip.getHostname());
service.connect(recip.getCompanyIdentifier());
service.loginInfo(recip.getUsername(), recip.getPassword());

//what kind of system am I connected to?
logger.info(service.system());
         
//Am I actually connected?            
boolean b = service.connected();
logger.info("connected: " + b);                     
            
//set my transfer type and change directories to the target dir         
service.setParameter(recip.getConnectMode(), "ascii");
service.changeDir(recip.getDestinationDir());
service.getDir();
                     
//now send the files...
for (Iterator it = a.iterator (); it.hasNext (); ) {
logger.info("Ready to transfer file...");
File f1 = (File) it.next ();
logger.info("File: " + f1.getName());
service.putFile(f1.getAbsolutePath(), f1.getName());

}   


but I am at a loss to explain the following issue When I attempt to transfer a file, I get the following output:

...
06 Jul 2007 - 17:23:54  [Timer-0] INFO  com.sm.directoryassistance.Reader - There are 15 files in /Export/
06 Jul 2007 - 17:23:54  [Timer-0] INFO  com.sm.ftp.FTPService - Connecting to ThomsonWest
06 Jul 2007 - 17:23:54  [Timer-0] INFO  com.sm.ftp.FTPService - Logging in...

4 Answers

0 votes
by (162k points)
Best to post a relevant snippet of our log file set to DEBUG level. Also print out the stack trace.
0 votes
by (220 points)
Per request, here is a snippet of the log output regarding my issue:

INFO [com.sm.ftp.FTPService] 9 Jul 2007 12:42:33.478 : Logging in...
DEBUG [FTPControlSocket] 9 Jul 2007 12:42:33.478 : ---> USER srcmd
DEBUG [FTPControlSocket] 9 Jul 2007 12:42:33.946 : 331 Need password for srcmd
DEBUG [FTPControlSocket] 9 Jul 2007 12:42:33.946 : ---> PASS ********
DEBUG [FTPControlSocket] 9 Jul 2007 12:42:34.709 : 230 User logged in, proceed.
DEBUG [FTPControlSocket] 9 Jul 2007 12:42:34.710 : ---> SYST
DEBUG [FTPControlSocket] 9 Jul 2007 12:42:35.211 : 215 UNIX
09 Jul 2007 - 12:42:35  [Timer-0] INFO  com.sm.application.XMLOps - UNIX
09 Jul 2007 - 12:42:35  [Timer-0] INFO  com.sm.application.XMLOps - connected: true
DEBUG [com.sm.ftp.FTPService] 9 Jul 2007 12:42:35.212 : Setting up transfers
DEBUG [FTPControlSocket] 9 Jul 2007 12:42:35.213 : ---> TYPE A
DEBUG [FTPControlSocket] 9 Jul 2007 12:42:35.663 : 200 Type set to A.
INFO [com.sm.ftp.FTPService] 9 Jul 2007 12:42:35.663 : changing directory to upload
DEBUG [FTPControlSocket] 9 Jul 2007 12:42:35.664 : ---> CWD upload
DEBUG [FTPControlSocket] 9 Jul 2007 12:42:36.147 : 250 CWD to /upload/ Successful.
DEBUG [com.sm.ftp.FTPService] 9 Jul 2007 12:42:36.147 : Directory after put
DEBUG [FTPControlSocket] 9 Jul 2007 12:42:36.152 : ---> PORT 0,0,0,0,219,73
09 Jul 2007 - 12:42:36  [Timer-0] WARN  com.sm.application.XMLOps - Exception: java.net.SocketException: Connection reset


The most obvious thing is that the FTPControlSocket reports that I am accessing 0.0.0.0, but I don't know why...

Any ideas or assistance would be greatly appreciated!

Thanks in Advance!!!
0 votes
by (162k points)
0.0.0.0 is why you are getting the problem.

Call setActiveIPAddress() with your hostname and that should fix this.
0 votes
by (220 points)
Looks like I am good to go... thanks for your help!!

Categories

...