Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
9.2k views
in Java FTP by
Hi,

I'm trying to get edtftp to download all the files in a directory and issue delete commands after each file is downloaded. I'm getting a "421 invalid command during xfer" error when the line ftp.delete(...) is reached. When used with FTPS, the program would just get stucked. I'm thinking this might be the "get" command was still running while the "delete" command was sent. Does anyone here know how do I get around this? Is there a method that I can call to let the "get" finish first before the "delete" is sent?

Here's the trace:

DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:58.924 : ---> USER datstat
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:58.934 : 331 Password required
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:58.934 : ---> PASS ********
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:58.934 : 230 user logged in
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:58.934 : ---> CWD TEST-FTPS/flatfiles
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:58.944 : 250 CWD successful
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:58.964 : ---> SYST
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:58.964 : 215 UNIX
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:58.974 : ---> PASV
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:58.974 : 227 Entering Passive Mode (127,0,0,1,7,191).
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:59.34 : ---> LIST
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:59.44 : 150 Opening ASCII data connection for directory listing
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:59.144 : 226 transfer complete
.
..
Armored.txt
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:59.154 : ---> PASV
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:59.164 : 227 Entering Passive Mode (127,0,0,1,7,193).
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:59.184 : ---> RETR Armored.txt
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:59.194 : 150 Opening BINARY data connection for Armored.txt (148069 bytes)
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:59.384 : 226 transfer complete
com.enterprisedt.net.ftp.FTPException: invalid command during xfer
at com.enterprisedt.net.ftp.FTPControlSocket.validateReply(Unknown Source)
at com.enterprisedt.net.ftp.FTPClient.delete(Unknown Source)
at test.FtpTest.main(FtpTest.java:30)
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:59.384 : ---> DELE Armored.txt
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 15:10:59.384 : 421 invalid command during xfer

And here's my code:

    try {
      FTPClient ftp = new FTPClient("localhost");
      ftp.debugResponses(true);
      ftp.login("datstat", "******");
      ftp.chdir("TEST-FTPS/flatfiles");
      FTPFile files[] = ftp.dirDetails("");
      for (int i = 0; i < files.length; i++) {
        System.out.println(files[i].getName());
      }
      ftp.get("test.txt", files[files.length - 1].getName());
      
      ftp.delete(files[files.length - 1].getName());
      ftp.quit();
    } catch (Exception e) {
      e.printStackTrace();
    }


Thanks a bunch.

Yongtze Chi

4 Answers

0 votes
by
I got the error when ran against a WS_FTP server on localhost. But everything worked fine when tested against another server. It might be related to the server, and not edtftp itself. Hmm...

Thanks.

Yongtze Chi
0 votes
by (162k points)
What server are you running against? Is this using edtFTPj/SSL, via FTPS? Does this happen with plain FTP?

If you are using edtFTPj/SSL, you may want to try some of the config flag settings such as DISABLE_DATA_SSL_CLOSURE, documented in the Javadoc.

Hi,

I'm trying to get edtftp to download all the files in a directory and issue delete commands after each file is downloaded. I'm getting a "421 invalid command during xfer" error when the line ftp.delete(...) is reached. When used with FTPS, the program would just get stucked. I'm thinking this might be the "get" command was still running while the "delete" command was sent. Does anyone here know how do I get around this? Is there a method that I can call to let the "get" finish first before the "delete" is sent?
0 votes
by
I get the error condition when I ran it against an Ipswitch WS_FTP Server. This happens for both FTP and FTPS. For the plain FTP version of my program, I get the error messages shown above. The FTPS version of my program get stucked when trying to send the "delete" command:

DEBUG [com.enterprisedt.net.ftp.ssl.SSLFTPClient] 18 Oct 2004 16:29:28.415 : Connecting to localhost/127.0.0.1:21
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:28.565 : 220-localhost X2 WS_FTP Server 5.0.2.EVAL (62395827)
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:28.565 : 220-Mon Oct 18 16:29:28 2004
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:28.575 : 220 localhost X2 WS_FTP Server 5.0.2.EVAL (62395827)
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:28.585 : ---> AUTH SSL
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:29.86 : 234 SSL enabled and waiting for negotiation
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:29.86 : Starting SSL handshake on control socket
INFO [puretls] 18 Oct 2004 16:29:29.727 : PureTLS debug level=0
INFO [cryptix] 18 Oct 2004 16:29:30.27 : GLOBAL_TRACE=false
INFO [cryptix] 18 Oct 2004 16:29:30.27 : GLOBAL_DEBUG=false
INFO [cryptix] 18 Oct 2004 16:29:30.27 : GLOBAL_DEBUG_SLOW=false
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.498 : SSL handshake on control socket complete
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.498 : ---> PBSZ 0
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.508 : 200 PBSZ=0
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.508 : ---> PROT P
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.508 : 200 PRIVATE data channel protection level set
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.508 : ---> USER datstat
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.518 : 331 Password required
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.518 : ---> PASS ********
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.518 : 230 user logged in
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.518 : ---> PBSZ 0
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.558 : 200 PBSZ=0
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.558 : ---> PROT P
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.568 : 200 PRIVATE data channel protection level set
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.568 : ---> CWD TEST-FTPS/flatfiles
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.568 : 250 CWD successful
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.588 : ---> SYST
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.598 : 215 UNIX
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.648 : ---> PASV
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.648 : 227 Entering Passive Mode (127,0,0,1,8,118).
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.648 : Creating SSLFTPPassiveDataSocket
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.668 : ---> LIST
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.668 : 150 Opening ASCII data connection for directory listing
DEBUG [com.enterprisedt.net.ftp.ssl.SSLFTPPassiveDataSocket] 18 Oct 2004 16:29:30.678 : Starting SSL handshake on passive data socket
DEBUG [com.enterprisedt.net.ftp.ssl.SSLFTPPassiveDataSocket] 18 Oct 2004 16:29:30.828 : SSL handshake on passive data socket complete
DEBUG [com.enterprisedt.net.ftp.ssl.SSLFTPPassiveDataSocket] 18 Oct 2004 16:29:30.838 : Closing socket on control socket
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.949 : 226 transfer complete
[.]
[..]
Armored.txt
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.959 : ---> TYPE I
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.959 : 200 Type set to IMAGE.
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.959 : ---> PASV
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.969 : 227 Entering Passive Mode (127,0,0,1,8,120).
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.969 : Creating SSLFTPPassiveDataSocket
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.979 : ---> RETR Armored.txt
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:30.979 : 150 Opening BINARY data connection for Armored.txt (148069 bytes)
DEBUG [com.enterprisedt.net.ftp.ssl.SSLFTPPassiveDataSocket] 18 Oct 2004 16:29:30.979 : Starting SSL handshake on passive data socket
DEBUG [com.enterprisedt.net.ftp.ssl.SSLFTPPassiveDataSocket] 18 Oct 2004 16:29:31.109 : SSL handshake on passive data socket complete
DEBUG [com.enterprisedt.net.ftp.ssl.SSLFTPPassiveDataSocket] 18 Oct 2004 16:29:31.359 : Closing socket on control socket
DEBUG [com.enterprisedt.net.ftp.FTPClient] 18 Oct 2004 16:29:31.369 : Transferred 148069 bytes from remote host
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:31.469 : 226 transfer complete
Trying to delete file Armored.txt
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 18 Oct 2004 16:29:31.469 : ---> DELE Armored.txt

For the SSL verion, I used these flags:
    ftp = new SSLFTPClient("localhost",
        SSLFTPClient.ConfigFlags.DISABLE_SSL_CLOSURE
        | SSLFTPClient.ConfigFlags.DISABLE_WAIT_ON_CLOSE
        | SSLFTPClient.ConfigFlags.DISABLE_CONTROL_SSL_CLOSURE
        | SSLFTPClient.ConfigFlags.DISABLE_CONTROL_WAIT_ON_CLOSE
        | SSLFTPClient.ConfigFlags.DISABLE_DATA_SSL_CLOSURE
        | SSLFTPClient.ConfigFlags.DISABLE_DATA_WAIT_ON_CLOSE);


However, when I ran the plain FTP version of my program against another server, everything worked just fine. I'm not sure if this is specific to the WS_FTP server I'm running, or if this is something else.

Thanks for your help.

What server are you running against? Is this using edtFTPj/SSL, via FTPS? Does this happen with plain FTP?

If you are using edtFTPj/SSL, you may want to try some of the config flag settings such as DISABLE_DATA_SSL_CLOSURE, documented in the Javadoc.

0 votes
by (162k points)
This could be a WS_FTP bug. The only google reference to this error also refers to WS_FTP.

I get the error condition when I ran it against an Ipswitch WS_FTP Server. This happens for both FTP and FTPS.

Categories

...