Skip to main content
Level 1
Nov 4, 2026 12:21 PM UTC
Question

Export a Content pages as a package(.zip) from AEM to FTP (port 21) location

From AEM I am trying to export a content package from AEM to FTP location of port 21 I am having FTP server credentials, from AEM local instance I am able to export the content package to FTP location verified in FileZilla, configured the dynamic variables and deployed to DEV. In DEV I am getting error like:-
 

ERROR [sling-threadpool-dfa082d7-49da-4b80-baf5-c55e7572c283-(apache-sling-job-thread-pool)-29-<main queue>(com/upcom/jobs/export-last24hr-package)] com.upcom.core.schedulers.contentpackageexport.ContentPackageExportJobConsumer FTP upload failure. Host=[proxy.tunnel], Port=[30021], Error=[Connection refused]

java.net.ConnectException: Connection refused

at java.base/sun.nio.ch.Net.pollConnect(Native Method)

at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:690)

at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542)

at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:592)

at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)

at java.base/java.net.Socket.connect(Socket.java:751)

at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:769) [com.upcom.aem-upcom-project.core:0.0.1.SNAPSHOT]

at org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:946) [com.upcom.aem-upcom-project.core:0.0.1.SNAPSHOT]

at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:3274) [com.upcom.aem-upcom-project.core:0.0.1.SNAPSHOT]

at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:3295) [com.upcom.aem-upcom-project.core:0.0.1.SNAPSHOT]

at com.upcom.core.schedulers.contentpackageexport.ContentPackageExportJobConsumer.uploadToFtp(ContentPackageExportJobConsumer.java:226) [com.upcom.aem-upcom-project.core:0.0.1.SNAPSHOT]

at com.upcom.core.schedulers.contentpackageexport.ContentPackageExportJobConsumer.exportLast24HourPackage(ContentPackageExportJobConsumer.java:126) [com.upcom.aem-upcom-project.core:0.0.1.SNAPSHOT]

at com.upcom.core.schedulers.contentpackageexport.ContentPackageExportScheduler.process(ContentPackageExportScheduler.java:99) [com.upcom.aem-upcom-project.core:0.0.1.SNAPSHOT]

at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:566) [org.apache.sling.event:4.4.2]

at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:381) [org.apache.sling.event:4.4.2]

at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:58) [org.apache.sling.event:4.4.2]

at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:308) [org.apache.sling.event:4.4.2]

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)

at java.base/java.lang.Thread.run(Thread.java:1583) 
Getting above error at boolean stored = ftpClient.storeFile(fileName, inputStream);

below is the code I am using to upload the package to FTP

private void uploadToFtp(String fileName, byte[] data) throws IOException {    FTPClient ftpClient = new FTPClient();    try {        ftpClient.connect(ftpHost, ftpPort);        int replyCode = ftpClient.getReplyCode();        if (!FTPReply.isPositiveCompletion(replyCode)) {            throw new IOException("FTP server refused connection. Host: " + ftpHost                    + ". Port: " + ftpPort + ". Reply code: " + replyCode);        }        if (!ftpClient.login(ftpUsername, ftpPassword)) {            throw new IOException("FTP login failed for user [" + ftpUsername                    + "] on host [" + ftpHost + "]. Reply: " + ftpClient.getReplyString());        }        ftpClient.enterLocalPassiveMode();        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);        String environment = resolveEnvironment();        String remoteDirectory = normalizeFtpPath(ftpFilePath) + environment;        changeToRemoteDirectoryFtp(ftpClient, remoteDirectory);        try (InputStream inputStream = new ByteArrayInputStream(data)) {            boolean stored = ftpClient.storeFile(fileName, inputStream);            if (!stored) {                throw new IOException("FTP upload failed for file [" + fileName                        + "]. Server reply: " + ftpClient.getReplyString());            }        }        LOG.info("Uploaded package [{}] to FTP path [{}]", fileName, remoteDirectory);    } catch (IOException e) {        throw new IOException(                "Unable to upload package to FTP. Host: " + ftpHost                        + ". Port: " + ftpPort                        + ". Error: " + e.getMessage(), e);    } finally {        try {            if (ftpClient.isConnected()) {                ftpClient.logout();                ftpClient.disconnect();            }        } catch (IOException ignored) {        }    }}

3 replies

shrutid56001193
User Group Leader
User Group Leader
Nov 4, 2026 12:52 PM UTC

The error indicates a network connectivity issue, not an issue with storeFile() itself.

AEM DEV is connecting to proxy.tunnel:30021, but the connection is being refused.

Check whether the DEV environment has network access to the FTP server and whether the proxy/port is correctly configured and allowlisted, if FTP is behind a VPN. Also verify the FTP data ports are reachable, since the stack trace shows the failure occurs while opening the data connection.

Translate
https://www.shrutidamle.com/
Level 1
Nov 5, 2026 1:43 PM UTC

The FTP user able to perform operations like:-
1.Successfully Login to FTP server
2.FTP reply code got 220 
3.Able to create environment specific directory at the FTP path provided
4.At establishing Data port connection getting Connection Refused

Verified above steps using log statements and any resolution to make Data port connection Successful to transmit the Data package Successfully.

Translate
Raja_Reddy
Community Advisor
Community Advisor
Nov 7, 2026 10:23 AM UTC

Hi ​@Venkata_NarayanaBa 
 

Since login, cwd and directory creation all work, the control connection through the proxy is fine. The failure is only in the data connection, and this is a known FTP passive mode problem with AEMaaCS Advanced Networking.

Why it happens

With enterLocalPassiveMode(), the FTP server replies to PASV with a random data port (for example 50123). commons-net then connects to proxy.tunnel:50123. The AEM proxy only listens on the ports you mapped in portForwards (30000-30999), and the port mapped to 21 is the only one set up. Nothing is listening on the passive port, so you get Connection refused at storeFile. It works locally because there is no proxy in between.

  1. Use SFTP (recommended). It uses a single connection on port 22, so one port-forward rule is enough and there is no separate data channel.
  2. Stay on FTP and pin the passive ports.
    • Ask the FTP server admin to restrict passive ports to a small range, for example 30100-30110, and advertise those same ports.
    • Add a port-forward rule for each passive port in your Advanced Networking configuration, alongside the control port:

json

   "portForwards": [
{ "name": "your-ftp-host", "portDest": 21, "portOrig": 30021 },
{ "name": "your-ftp-host", "portDest": 30100, "portOrig": 30100 },
{ "name": "your-ftp-host", "portDest": 30101, "portOrig": 30101 }
]

Passive ports need portOrig and portDest to be the same value, because the client connects to whatever port the server advertises.

Active mode won’t work, since the server would have to connect back into AEM.

Hope this helps. If you can share the PASV reply from your logs, I can help check the port mapping.

Translate