Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
10.1k views
in Java FTP by (440 points)
I got strange problems with one ftp-server.
I use edtftpj in my application to upload some files.
The problem:
Very often, I don't know when exactly, it seems that there is no connection any more or so.
im passive mode the log is printing -->pasv continuesly
in active mode it's printing -->port "strange ip's starting with 0.0.x.x" continuesly

I mailed the administrator of the server, as this problem does not occur on a different server and also not on my local ftp-server
but he can't help me.
The strange thing is that it occurs sometimes (often) but not always.
Is anything known about that? Maby any special setup required or so?

Thanks for your help

Frank

15 Answers

0 votes
by (51.6k points)
This sounds very mysterious. Is it possible for you to enable logging in edtFTPj and send us the log that shows the problem? That should help us to find out what's wrong. The Developer's Guide explains how to enable logging.

- Hans (EDT)
0 votes
by (440 points)
sure
I made 4 successful uploads and then this:
so it seems that I'm not logged, but i didn't change anything during the 5 attempts
i thought that the connect method does not block and inserted a loop after ftp.login
while(true)
{              
    if(ftp.getLastValidReply().getReplyCode().equals("230"))
    {                    
        break;
     }
}

maybe wrong or not necessary, as said it worked 4 times and then not
DEBUG [com.enterprisedt.net.ftp.FTPClient] 4 Jun 2006 13:44:52.562 : Connecting to /217.20.121.136:21
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 4 Jun 2006 13:44:52.625 : 220 FTP Server ready.
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 4 Jun 2006 13:44:52.625 : ---> USER xxxx
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 4 Jun 2006 13:44:52.656 : 331 Password required for xxxx.
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 4 Jun 2006 13:44:52.656 : ---> PASS ********
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 4 Jun 2006 13:44:52.750 : ---> PASV
DEBUG [com.enterprisedt.net.ftp.FTPClient] 4 Jun 2006 13:44:52.750 : Transferred 0 bytes to remote host
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 4 Jun 2006 13:44:52.750 : ---> PASV
DEBUG [com.enterprisedt.net.ftp.FTPClient] 4 Jun 2006 13:44:52.750 : Transferred 0 bytes to remote host
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 4 Jun 2006 13:44:52.750 : ---> PASV
DEBUG [com.enterprisedt.net.ftp.FTPClient] 4 Jun 2006 13:44:52.750 : Transferred 0 bytes to remote host
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 4 Jun 2006 13:44:52.750 : ---> PASV
DEBUG [com.enterprisedt.net.ftp.FTPClient] 4 Jun 2006 13:44:52.750 : Transferred 0 bytes to remote host
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 4 Jun 2006 13:44:52.750 : ---> PASV
DEBUG [com.enterprisedt.net.ftp.FTPClient] 4 Jun 2006 13:44:52.750 : Transferred 0 bytes to remote host

and so on...
0 votes
by (440 points)
I now worried that it is the loop, but i recompiled without the loop and again the error.
This time in in the second attempt
0 votes
by (51.6k points)
Can you please post a bit more of the code?

- Hans (EDT)
0 votes
by (440 points)
It is basically that of the demo,
i tried many differnet versions:

login(user,password)

login()
user()
password()

active/passive mode

setting the mode befoe and after login

and always it worked sometimes sometimes not
so i believe it's not ftpj now, it's the server, but maybe you as a developer of an ftp server are more expierenced than the admin of the server
he sais that this image of the ftp server is running 3000 times without problems, but:
for example: when i use IE to login, than again, often not always a permission error is shown
when i update, I'm looged in

any ideas?
thanks for help
0 votes
by (51.6k points)
What I can't understand is how it comes about that the PASV command is sent more than once. I don't think the server could cause that. There must be a loop somewhere that is causing the PASV command to be sent repeatedly, yet I'm not aware of any of our code placing a PASV command invocation inside a loop. It'd be really helpful if you could post the actual code that demonstrates the problem so that we can analyse it.

- Hans (EDT)
0 votes
by (440 points)
yes there is a loop(thread) but later, after login and changing/creating dirs
this is the last version wih getLastValidReply()
as i said i also tried with login(user,password)
what about following scenario:
the login is done, and then the server closes the connection and ftpj is sending pasv
without knowing that the connection is closed because the server sends a wrong or none message?
and then , yes there must be a loop, as printed in debug

   public void ????() {
      try {
         ftp = new FTPClient();
         ftp.setMessageListener(new MyMessageListener());
         ftp.setProgressMonitor(this);
         ftp.setConnectMode(FTPConnectMode.PASV);
         ftp.setRemoteHost(Properties.IP_ADRESS);
         ftp.connect();
         if (ftp.connected()) {
            ftp.user(Properties.FTP_USER);
            if (ftp.getLastValidReply().getReplyCode().equals("331")) {
               ftp.password(Properties.FTP_PASSWORD);
            }
         }
// when the error occurs it doesn't come to this part / commands
// as printed in the debug log

         ftp.chdir("html/fileadmin/shootings/");
         boolean customerDirExists = false;
         String[] filenames = ftp.dir();
         for (int i = 0; i < filenames.length; i++) {
            if (filenames[i].equals(ftpCustomerDirName)) {
               customerDirExists = true;
               break;
            }
         }
         if (customerDirExists == false) {
            ftp.mkdir(ftpCustomerDirName);
         }

         ftp.chdir(ftpCustomerDirName);
         if (!isZipUpload) {
            try {
               ftp.mkdir(folderName);
               folderPath = Properties.dirPrefix + ftpCustomerDirName
                     + "/" + folderName;
            } catch (FTPException fe) {
               JOptionPane.showMessageDialog(myDesktop,
                     "Dieser Shooting Ordner existiert schon.");
               ftp.quit();
               dispose();
            }
            ftp.chdir(folderName);
         }

         ftp.setType(FTPTransferType.BINARY);
      } catch (IOException e) {
         e.printStackTrace();

      } catch (FTPException fe) {
         fe.printStackTrace();
      }

      Thread upl = new Thread(this);
      upl.start();
   }

   public void run() {
      int count = 0;
      while (count < picsToUpload.length) {
         try {
            ftp.put(picsToUpload[count].getAbsolutePath(),
                  picsToUpload[count].getName());
            count++;
         } catch (IOException ioe) {
            System.out.println("ioe-error");

         } catch (FTPException fe) {
            System.out.println("error");
         }
      }
      cleanup();
   }
    
0 votes
by (51.6k points)
I just can't see how the code you've posted could behave in the way you're describing, unless it's being called in ways other than what you expect. I suspect that this problem is caused by something outside of the code you're focussing on. If I were you I would implement the FTP code in a separate little test application and get it working first, and then move it back into your main application. Alternatively, including a lot logging throughout your code would also help. If you like, you can use com.enterprisedt.util.debug.Logger by:
Logger log = Logger.getLogger(MyClass.class);
...
log.debug("My logging message");


I'm sorry I can't be of more help, but I just can't see how this code - by itself - could produce that output. It doesn't seem possible to me.

- Hans (EDT)
0 votes
by (440 points)
Thanks for your help.
The mysterious thing is that the code works with other (one private and one other public) ftp-server.
So maybe you have an idea why sometimes (often) a ftp server closes the connection when logging in
although it's not your responsibility.
As I said this occurs also with ftp.exe and with the Internet Explorer.
And I have a router, but never had to setup anything to connect to a ftp sever.

I just read the source of ftpclient and found a loop in putData()
while ((count = in.read(buf)) > 0 && !cancelTransfer)

don't know where cancelTransfer is set but, if it can't be set to true because of a strange server reply
then i guess this repeated debug log appears

i guess this is nothing new to you, but i just want to do anything possible to get ftpj running with this server
for example in IE i click update and then I am logged, so maybe i can do this programmatically in my application when i
could catch the error/ false reply or so
0 votes
by (51.6k points)
Is it possible for you to send us a test program and the login details of a test account on the server you're experiencing problems with?

- Hans (EDT)

Categories

...