org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection.

YouTrack | 2 months ago
  1. 0

    Uploading multiple files via FTP fails

    GitHub | 3 years ago | yoan-m
    org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection.
  2. 0

    If the connection timeout defined for the FTP server is less than the poll period defined for the channel-adapter's poller, the pool will eventually contain connections that have been dropped by the server. This results in: {code} WARNING: Failure notification received by [FtpSource] for message: null org.springframework.integration.message.MessagingException: Error while polling for messages. at org.springframework.integration.adapter.file.AbstractDirectorySource.receive(AbstractDirectorySource.java:76) at org.springframework.integration.message.MessageExchangeTemplate.doReceive(MessageExchangeTemplate.java:212) at org.springframework.integration.message.MessageExchangeTemplate.doReceiveAndForward(MessageExchangeTemplate.java:231) at org.springframework.integration.message.MessageExchangeTemplate.receiveAndForward(MessageExchangeTemplate.java:191) at org.springframework.integration.dispatcher.PollingDispatcher.run(PollingDispatcher.java:127) at org.springframework.integration.scheduling.spi.ProviderTaskScheduler$TaskRunner.run(ProviderTaskScheduler.java:221) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source) at java.util.concurrent.FutureTask.runAndReset(Unknown Source) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection. at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:321) at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:460) at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:520) at org.apache.commons.net.ftp.FTP.port(FTP.java:849) at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:477) at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2390) at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2364) at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2141) at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2188) at org.springframework.integration.adapter.ftp.FtpSource.populateSnapshot(FtpSource.java:90) at org.springframework.integration.adapter.ftp.FtpSource.refreshSnapshotAndMarkProcessing(FtpSource.java:79) at org.springframework.integration.adapter.file.AbstractDirectorySource.receive(AbstractDirectorySource.java:68) ... 14 more {code} It's possible to send a NOOP (No Operation) command to the FTP Server before passing the FTPClient instance on. This should restart the "connection" timer. Here's a better version of QueuedFTPClientPool.getClient(): {code} public synchronized FTPClient getClient() throws SocketException, IOException { FTPClient client = null; boolean disconnected = true; while(disconnected) { client = pool.isEmpty() ? factory.getClient() : pool.poll(); try { if(client.sendNoOp()) disconnected = false; else disconnect(client); } catch (FTPConnectionClosedException e) { disconnect(client); } } return client; } private void disconnect(FTPClient client) { try { client.disconnect(); } catch(IOException e) { //Ignore or log } } {code} This is not perfect however, since FTP servers (at least FileZilla) also define a "no transfer timeout" (the time a user has to initiate a file transfer) in addition to the "connection timeout". There seems to be no way of restarting that timer, and if the poll period and the "no transfer timeout" are close enough to each other, we could see a race condition in which the client.sendNoOp() returns true and restarts the "connection" timer, but the "no transfer timeout" expires before the client gets to transfer a file and thus holds a "dead" connection. This should be documented so the user knows to either disable the "no transfer timeout" or to use a a pool size of zero to avoid potential problems.

    Spring JIRA | 8 years ago | Martti von Hertzen
    org.springframework.integration.message.MessagingException: Error while polling for messages.
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    MATLAB Central - Re: problem with mput & mget (file up/download to

    mathworks.com | 4 months ago
    org.apache.commons.net.ftp.FTPConnectionClosedException: FTP > response > 421 received. Server closed connection.
  5. 0

    Areca Backup / Discussion / Open Discussion:ftp timeouts

    sourceforge.net | 12 months ago
    org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection.

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.apache.commons.net.ftp.FTPConnectionClosedException

      FTP response 421 received. Server closed connection.

      at org.apache.commons.net.ftp.FTP.__getReply()
    2. Commons Net
      FTP.noop
      1. org.apache.commons.net.ftp.FTP.__getReply(FTP.java:367)
      2. org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
      3. org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:483)
      4. org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:608)
      5. org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:582)
      6. org.apache.commons.net.ftp.FTP.noop(FTP.java:1763)
      6 frames
    3. Commons VFS Core
      JBFtpKeepAliveCommand$1.invoke
      1. org.apache.commons.vfs2.provider.ftp.FTPClientWrapper.noop(FTPClientWrapper.java:488)
      2. org.apache.commons.vfs2.provider.ftp.JBFtpKeepAliveCommand$1.invoke(JBFtpKeepAliveCommand.java:10)
      2 frames
    4. JetBrains plugins
      PatchedFtpFileSystem$2.run
      1. com.jetbrains.plugins.webDeployment.connections.PatchedFtpFileSystem$2.run(PatchedFtpFileSystem.java:53)
      1 frame
    5. Openapi
      QueueProcessor.runSafely
      1. com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
      1 frame
    6. IDEA
      Alarm$Request.run
      1. com.intellij.util.Alarm$Request$1.run(Alarm.java:378)
      2. com.intellij.util.Alarm$Request.run(Alarm.java:389)
      2 frames
    7. Java RT
      FutureTask.run
      1. java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      2. java.util.concurrent.FutureTask.run(FutureTask.java:266)
      2 frames
    8. Openapi
      BoundedTaskExecutor$2.run
      1. com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:227)
      2. com.intellij.util.concurrency.BoundedTaskExecutor$2.run(BoundedTaskExecutor.java:187)
      2 frames
    9. Java RT
      Thread.run
      1. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      2. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      3. java.lang.Thread.run(Thread.java:745)
      3 frames