commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Justin.Z...@rrd.com
Subject org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication
Date Thu, 07 Dec 2006 18:41:52 GMT
Hi,

I got the exception when sending very large files, in this case it is >2G. 
For smaller files, FTPClient.storeFile() returns normally. However the big 
one will behave like following:


[2006-12-06 16:22:07] DEBUG - Sending '/tmp/ftp.test2' to 
xxx:xxx/xxx.xxx.com:53333/ftp/premedia/subdir1;type=i,connect=p

.....

[2006-12-06 17:45:09] ERROR - 
org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed 
without indication.
        at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:267)
        at org.apache.commons.net.ftp.FTP.getReply(FTP.java:605)
        at 
org.apache.commons.net.ftp.FTPClient.completePendingCommand(FTPClient.java:1253)
        at 
org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:415)
        at 
org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1388)
        at dams.services.ftp.worker.FTPer.send_file(FTPer.java:263)
        at dams.services.ftp.worker.FTPer.sendFile(FTPer.java:165)
        at 
dams.services.ftp.testers.FTPerTester.deliveryOneFileTest(FTPerTester.java:64)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at junit.framework.TestCase.runTest(TestCase.java:166)
        at junit.framework.TestCase.runBare(TestCase.java:140)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:131)
        at junit.framework.TestSuite.runTest(TestSuite.java:173)
        at junit.framework.TestSuite.run(TestSuite.java:168)
        at junit.textui.TestRunner.doRun(TestRunner.java:74)
        at junit.textui.TestRunner.run(TestRunner.java:200)
        at dams.services.ftp.testers.FTPerTester.main(FTPerTester.java:80)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
        at 
org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
        at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
        at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
        at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
        at 
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        at org.apache.tools.ant.Target.execute(Target.java:341)
        at org.apache.tools.ant.Target.performTasks(Target.java:369)
        at 
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
        at 
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
        at org.apache.tools.ant.Main.runBuild(Main.java:668)
        at org.apache.tools.ant.Main.startAnt(Main.java:187)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)


The code snippet looks like this:

........
this.controlTimeout = 300000; //5 minutes
this.dataTimeout = 10800000; //3 hours
this.readerThread = false;

....
private void send_file() {
        status = STATUS_NONE;
        logger.debug("Sending '" + this.file + "' to " + destination
.toString());
        try {
            if (keepAlive == false || ftp.isConnected() == false) {
                ftp.setReaderThread(this.readerThread);
                ftp.setDefaultTimeout(this.controlTimeout);
                ftp.connect(destination.getHost(), destination.getPort());

                // After connection attempt, you should check the reply 
code to
                // verify success

                int reply = ftp.getReplyCode();
                logger.debug("reply=" + reply);
                if (!FTPReply.isPositiveCompletion(reply)) {
                    status = STATUS_CONNECTION_REFUSED;
                    stringStatus = "FTP server refused connection.";
                }
                else if (!ftp.login(destination.getUsername(), destination
.getPassword())) {
                    status = STATUS_LOGIN_FAILED;
                    stringStatus = "Error logging in to server.";
                }
            }

            if (status == STATUS_NONE) {
                ftp.setDataTimeout(this.dataTimeout);
                //ftp.setReaderThread(this.readerThread);
                String dir = destination.getDirectory();

                if ("a".equals(destination.getMode()))
                    ftp.setFileType(FTP.ASCII_FILE_TYPE);
                else
                    ftp.setFileType(FTP.BINARY_FILE_TYPE);

                if ("p".equals(destination.getControl()))
                    ftp.enterLocalPassiveMode();
                else
                    ftp.enterLocalActiveMode();

                // change working directory
                if (dir != null && !ftp.changeWorkingDirectory(dir)) {
                    StringTokenizer st = new StringTokenizer(dir, "/");
                    while (st.hasMoreTokens()) {
                        String subdir = st.nextToken();
                        if (!ftp.changeWorkingDirectory(subdir)) {
                            if (!ftp.makeDirectory(subdir)) {
                                status = STATUS_BAD_DIRECTORY;
                                stringStatus = "Change directory failed: " 
+ ftp.getReplyString();
                                break;
                            }
                            if (!ftp.changeWorkingDirectory(subdir)) {
                                status = STATUS_BAD_DIRECTORY;
                                stringStatus = "Change directory failed: " 
+ ftp.getReplyString();
                                break;
                            }
                        }
                    }
                }
            }

            logger.debug("noop=" + ftp.noop());
            if (status == STATUS_NONE) {
                File f = new File(file);
                InputStream input = new FileInputStream(f);
                long start = new Date().getTime();
                try {
                    if (ftp.storeFile(f.getName(), input)) {
                        status = STATUS_SUCCESS;
                        stringStatus = "FTP succeeded: " + ftp
.getReplyString();
                    }
                    else {
                        status = STATUS_TRANSFER_FAILED;
                        stringStatus = "Transfer failed: " + ftp
.getReplyString();
                    }
                }
                finally {
                    input.close();
                }

        .....
        }

My understanding is the control input stream timed out in the 
__getReply(). But what the cause it can be? FTP server closes the 
connection, or the control socket just died?

Thanks in advance?

Justin
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message