示例#1
0
  /**
   * Opens a new connection and performs login with user name and password if set.
   *
   * @throws IOException
   */
  protected void connectAndLogin() throws IOException {
    if (!ftpClient.isConnected()) {
      ftpClient.connect(getEndpointConfiguration().getHost(), getEndpointConfiguration().getPort());

      log.info("Connected to FTP server: " + ftpClient.getReplyString());

      int reply = ftpClient.getReplyCode();

      if (!FTPReply.isPositiveCompletion(reply)) {
        throw new CitrusRuntimeException("FTP server refused connection.");
      }

      log.info("Successfully opened connection to FTP server");

      if (getEndpointConfiguration().getUser() != null) {
        log.info(String.format("Login as user: '******'", getEndpointConfiguration().getUser()));
        boolean login =
            ftpClient.login(
                getEndpointConfiguration().getUser(), getEndpointConfiguration().getPassword());

        if (!login) {
          throw new CitrusRuntimeException(
              String.format(
                  "Failed to login to FTP server using credentials: %s:%s",
                  getEndpointConfiguration().getUser(), getEndpointConfiguration().getPassword()));
        }
      }
    }
  }
示例#2
0
  @Override
  public void destroy() throws Exception {
    if (ftpClient.isConnected()) {
      ftpClient.logout();

      try {
        ftpClient.disconnect();
      } catch (IOException e) {
        log.warn("Failed to disconnect from FTP server", e);
      }

      log.info("Successfully closed connection to FTP server");
    }
  }
示例#3
0
 public void close() throws Exception {
   if (isClosed) {
     System.out.println("SSH source already closed!");
     return;
   }
   System.out.println("Closing SSH log source..");
   isClosed = true;
   ftpReadThread.interrupt();
   if (reader != null)
     try {
       reader.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   if (client != null && client.isConnected()) {
     System.out.println("try to disconnect SSH channel");
     client.disconnect(true);
     System.out.println("FTP  disconnected");
   }
   buffer.clear();
 }
示例#4
0
 private void checkConnection() {
   if (!ftpClient.isConnected()) connect();
 }