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) {        }    }}

1 reply

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/