I’m using Camel 2.15.2 with Apache Commons Net 3.3 on Java 8 deployed into a Tomcat container.
The issue is that consistently after processing just over 200 files (> 4000 files in the directory) the route stops, the FTP client disconnects and the following message is logged out:
[ogs.sharp-stream.com:21/root/] FtpConsumer WARN Error processing file RemoteFile[route/to/file] due to File operation failed: Connection closed without indication.. Code: 421. Caused by: [org.apache.camel.component.file.GenericFileOperationFailedException - File operation failed: Connection closed without indication.. Code: 421]
org.apache.camel.component.file.GenericFileOperationFailedException: File operation failed: Connection closed without indication.. Code: 421
at org.apache.camel.component.file.remote.FtpOperations.getCurrentDirectory(FtpOperations.java:713)
at org.apache.camel.component.file.remote.FtpOperations.retrieveFileToFileInLocalWorkDirectory(FtpOperations.java:440)
at org.apache.camel.component.file.remote.FtpOperations.retrieveFile(FtpOperations.java:310)
at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:384)
at org.apache.camel.component.file.remote.RemoteFileConsumer.processExchange(RemoteFileConsumer.java:137)
at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:211)
at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:175)
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187)
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:317)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:483)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:608)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:582)
at org.apache.commons.net.ftp.FTP.pwd(FTP.java:1454)
at org.apache.commons.net.ftp.FTPClient.printWorkingDirectory(FTPClient.java:2658)
at org.apache.camel.component.file.remote.FtpOperations.getCurrentDirectory(FtpOperations.java:709)
... 15 more
This is the URI used at the begining of the related route.
As you can tell from the URI I’m also using a FileIdempotentRepository. It’s defined like this
<property name="fileStore" value="target/fileidempotent/.filestore1.dat" />
<property name="maxFileStoreSize" value="512000" />
<property name="cacheSize" value="250" />
</bean>
Any ideas why the connection might be closing before all files are processed?
org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
Please follow the issue template and provide more details. issues like this do not provide any way of replicating the problem and spotting if it’s an Apache Commons FTP bug or an Android Upload Service bug. Thank you!
English is poor, please forgive me。
Using FTP to upload files to the window server was correct yesterday, but it went wrong today. The device system is android4.4.4
Sorry, but you have to follow what is in the issue template and provide necessary details, otherwise I couldn’t help you in any way
The same file, second pass will make mistakes ,and return «Error while uploading: xx to xx»
I don’t understand the code
try { String remoteFileName = getRemoteFileName(file); if (!ftpClient.storeFile(remoteFileName, localStream)) { throw new IOException("Error while uploading: " + file.getName(service) + " to: " + file.getProperty(PARAM_REMOTE_PATH)); } setPermission(remoteFileName, file.getProperty(PARAM_PERMISSIONS)); } finally { localStream.close(); }
The exception is thrown because the transfer of the file to your FTP directory is not possible. I don’t have the Apache Commons Net FTP docs at hand, but this may be due to permission policy for your FTP user or if the file already exists, in which case it doesn’t get overwritten.
Can you successfully upload the file for the first time? If I understand correctly, you get the exception only the second time you try to upload it.
Successfully upload the file for the first time.But,Some FTP servers can upload second times。
I’ll see if the FTP service is insufficient。
Example:
new FTPUploadRequest(mContext, _ip, _port)
.setUsernameAndPassword(_accout, _pwd)
.addFileToUpload(path, to)
.setNotificationConfig(config)
.setCreatedDirectoriesPermissions(new UnixPermissions(«777»))
.setSocketTimeout(301000)
.setConnectTimeout(301000)
Here it’s storeFile method JavaDoc. The method should overwrite the existing file the second time you try to make an upload.
The best way to check if the problem is in the library or in your FTP server config is to use one of the test FTP servers
You are right,this is FTP server Permission denied。
thanks
Below sample code is used with BPXBATCH to Connect to a MAINFRAME FTP Client.
When I run the below from Eclipse on my windows PC. its Successfull.
The issue comes when I try to execute the same with BPXBATCH on a Mainframe.
The code throws an FTPConnectionClosedException : Connection closed without indication
at client.connect(«XXX.XXX.XXX.XXX»);
FTPClient client = new FTPClient();
try {
client.connect("XXX.XXX.XXX.XXX");
client.login("user1", "pass123");
int reply ;
reply = client.getReplyCode();
System.out.println("Reply Code:"+reply);
if(client.isConnected())
client.logout();
else
System.out.println("Negative reply");
} catch(final Throwable t){
t.printStackTrace();
}
Error message
FTP Upload Document ORG.Apache.commons.Net.ftp.ftpConnectionClosedexception: Connection Closed WITHOUT INDINATION Error
The project is migrated because the FTP is migrated, and the ftpclient login is successful, but the upload file will be reported to this error.
Code
public boolean uploadFile(String ip, int port, String username,
String password, String serverpath, String file) {
// Initial indication of upload failed
boolean success = false;
// Create an FTPClient object
FTPClient ftp = new FTPClient();
ftp.setControlEncoding("UTF-8");
ftp.setConnectTimeout(20000);
ftp.setDataTimeout(600000);
ftp.enterLocalPassiveMode();
ftp.setActivePortRange(4000, 4100);
try {
int reply=0;
/ / Connect the FTP server
// If you use the default port, you can use the ftp.connect (IP) to connect the FTP server directly.
ftp.connect(ip, port);
//ftp.connect("192.168.20.221", 21);
// Log in to FTP
ftp.login(username, password);
/ / Look at the return value is reply> = 200 & application <300 if it is, indicating that the landing is successful
reply = ftp.getReplyCode();
logger.info("Connect the FTP server response code, reply = {}",reply);
// The return value starting with 2 will be true
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return success;
}
ftp.setActivePortRange(40000, 41000);
logger.info("FTP connection success ... file = {}, serverPath = {}", file, serverpath);
checkPathExist(ftp,iso8859ToGbk(serverpath));
// input stream
InputStream input=null;
try {
file=gbkToIso8859(file);
input = new FileInputStream(iso8859ToGbk(file));
} catch (Exception e) {
LoggerFactory.getLogger(this.getClass()).error("Read upload file error",e);
}
// Store uploaded files to the specified directory
file=iso8859ToGbk(file);
String fileName = getFilename(file);//8859
int index = fileName.lastIndexOf(".");
String tmpFileName = fileName.substring(0,index)+".tmp";
ftp.deleteFile(iso8859ToGbk(fileName));
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
String ftpPath = iso8859ToGbk(serverpath)+"/"+iso8859ToGbk(tmpFileName);
logger.info("Upload before ftp path, ftppath = {}",ftpPath);
boolean flag = ftp.storeFile(ftpPath, input);
logger.info("After uploading the document, the upload result flag = {}", flag);
// Turn off the input stream
input.close();
if(flag){
ftp.rename(iso8859ToGbk(serverpath)+"/"+iso8859ToGbk(tmpFileName),
iso8859ToGbk(serverpath)+"/"+iso8859ToGbk(fileName));
success = true;
}
// Exit FTP
ftp.logout();
} catch (IOException e) {
success = false;
LoggerFactory.getLogger(this.getClass()).error("Upload data to FTP error",e);
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
LoggerFactory.getLogger(this.getClass()).info(ioe.toString());
}
}
}
return success;
}
FTP master passive mode introduction
Active mode: The FTP client sends a connection request to the server’s FTP control port (default is 21), the server accepts the connection, establish a command link; when the data is required, the client uses port to tell the server with port on the command link. I opened a port, and you came over to connect me. So the server sends a connection request from the 20-port of the port to the client, and establish a data link to transmit data. In the data link establishment, the server active request is called, so it is called active mode.
Passive mode: FTP client sends a connection request to the server’s FTP control port (default 21), the server accepts the connection, establish a command link; when you need to transfer data, the server uses the PASV command to tell the client with the PASV command on the command link, I Open a port, you come over. So the client sends a connection request to the server of the server, and a data link is created to transmit data. In the process of establishing the data link, it is a request for the server passive waiting client, so it is called passive mode.
Cause Analysis
Looking at the code above, you know that after the FTP login is successful, the ftp.setactiveportRange (40000, 41000) is executed; this means that the active mode is transmitted, and the active mode requires the FTP server to connect our port, result, due to network problems The FTP server cannot connect to the client’s port, so this error is reported.
solution
For this problem, there should be two solutions: 1. Open the network, is the port that the FTP server can connect to the client 40000 ~ 41000; Second, it is changed to passive mode.
Here I take the second method: After the FTP client login is successful (it is invalid before logging in), perform ftp.enterlocalpassivemode (); it is possible, the final code is as follows:
public boolean uploadFile(String ip, int port, String username,
String password, String serverpath, String file) {
// Initial indication of upload failed
boolean success = false;
// Create an FTPClient object
FTPClient ftp = new FTPClient();
ftp.setControlEncoding("UTF-8");
ftp.setConnectTimeout(20000);
ftp.setDataTimeout(600000);
ftp.enterLocalPassiveMode();
ftp.setActivePortRange(4000, 4100);
try {
int reply=0;
/ / Connect the FTP server
// If you use the default port, you can use the ftp.connect (IP) to connect the FTP server directly.
ftp.connect(ip, port);
//ftp.connect("192.168.20.221", 21);
// Log in to FTP
ftp.login(username, password);
/ / Look at the return value is reply> = 200 & application <300 if it is, indicating that the landing is successful
reply = ftp.getReplyCode();
logger.info("Connect the FTP server response code, reply = {}",reply);
// The return value starting with 2 will be true
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return success;
}
ftp.enterLocalPassiveMode();// This is changed to passive mode
logger.info("FTP connection success ... file = {}, serverPath = {}", file, serverpath);
checkPathExist(ftp,iso8859ToGbk(serverpath));
// input stream
InputStream input=null;
try {
file=gbkToIso8859(file);
input = new FileInputStream(iso8859ToGbk(file));
} catch (Exception e) {
LoggerFactory.getLogger(this.getClass()).error("Read upload file error",e);
}
// Store uploaded files to the specified directory
file=iso8859ToGbk(file);
String fileName = getFilename(file);//8859
int index = fileName.lastIndexOf(".");
String tmpFileName = fileName.substring(0,index)+".tmp";
ftp.deleteFile(iso8859ToGbk(fileName));
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
String ftpPath = iso8859ToGbk(serverpath)+"/"+iso8859ToGbk(tmpFileName);
logger.info("Upload before ftp path, ftppath = {}",ftpPath);
boolean flag = ftp.storeFile(ftpPath, input);
logger.info("After uploading the document, the upload result flag = {}", flag);
// Turn off the input stream
input.close();
if(flag){
ftp.rename(iso8859ToGbk(serverpath)+"/"+iso8859ToGbk(tmpFileName),
iso8859ToGbk(serverpath)+"/"+iso8859ToGbk(fileName));
success = true;
}
// Exit FTP
ftp.logout();
} catch (IOException e) {
success = false;
LoggerFactory.getLogger(this.getClass()).error("Upload data to FTP error",e);
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
LoggerFactory.getLogger(this.getClass()).info(ioe.toString());
}
}
}
return success;
}
It is expected to help everyone.
Эта ошибка возникает на файлы загрузки Linux, используя ftpclient
org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:317)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:483)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:608)
at org.apache.commons.net.ftp.FTP.cwd(FTP.java:828)
at org.apache.commons.net.ftp.FTPClient.changeWorkingDirectory(FTPClient.java:1128)
at com.taotao.test.FTPTest.testFTP(FTPTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
В конце концов, путем изменения разрешений файла на сервере его можно успешно выполнить, и этот метод использовался для сохранения файла для открытия разрешений этого пользователя для выполнения (X), я напрямую устанавливаю (rwx)