Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.7k views
in Java FTP by
Hi,

I have the following code in a JUnit test:
public void testUploadFtp() {
      
   FtpWrapper ftp = null;
   try {
      ftp = new FtpWrapper(path);
      
      ftp.connectAndLogin(serverName, userName, password);
      logger.info("Conectado " + serverName);
               
      String contenido = "contenido";
      ftp.uploadFile(contenido, "ficherin.txt");
      ftp.disconnect();
   } catch(Exception e) {
      logger.error(e);
      fail(e.getMessage());
   }
}

The FtpWrapper class is a subclass of com.enterprisedt.net.ftp.FTPClient. Its code is:
public class FtpWrapper extends FTPClient{
   
   private static Logger logger = Logger.getLogger(FtpWrapper.class);
      
   private String path = null;
      
   public FtpWrapper(String path) throws  IOException, FTPException {
      super();
      this.path = path;            
   }
   
   
   public boolean connectAndLogin (String host, String userName, String password)
         throws  IOException, FTPException {
      boolean success = false;
      logger.info("Initializing connection.");
      setRemoteHost(host);
      connect();
      login(userName, password);
      if(!connected()){
         disconnect();
      }
      return success;
   }
      
   public void  uploadFile (String content, String serverFile) 
         throws IOException, FTPException {
      
      logger.info("Transfer file "+serverFile);
      if(path!=null){
         logger.info("To path "+         chdir(path);
      }
      
      put(content.getBytes(), serverFile);
   }
   
   public void disconnect() throws IOException, FTPException {
      logger.info("Disconnecting...");
      quit();
   }
}

The error I get is this:
0 [main] INFO - Inicializando par

3 Answers

0 votes
by (140 points)
Has probado a poner un timeout alto
0 votes
by (180 points)
Has probado a poner un timeout alto
0 votes
by (180 points)
I've got the answer. I have to set the ACTIVE mode.

setConnectMode(FTPConnectMode.ACTIVE);

Adding this command the problem is solved.

Thanks.

Categories

...