Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
6.4k views
in Java FTP by (320 points)
Hi all,

In my application i want to do some operation if the connection breaks between the two machines while transferring the file.No time out will be set.
Is there any way to find out the lose of connection immediately ?? I'm thinking of using the noOperation method from a seperate thread.
Help me in overcoimg this problem.

Cheers,
Krish.

10 Answers

0 votes
by (162k points)
You should get an IOException thrown immediately.

Hi all,

In my application i want to do some operation if the connection breaks between the two machines while transferring the file.No time out will be set.
Is there any way to find out the lose of connection immediately ?? I'm thinking of using the noOperation method from a seperate thread.
Help me in overcoimg this problem.

Cheers,
Krish.
0 votes
by (320 points)
Hi Support2,

Thanks for your reply.
This is what i expected but I never get an IOException thrown when i unplug the network card from one of the two machines while the transfer is going on.
We have been using one of the older version and found that noOperation method is not there in the FTPClient.I have to use this version only since we have no plans for the upgrade now.

This is critical Please guide me..

Thanks,
Krish.
0 votes
by (320 points)
Hi All,

Any ideas to solve this probelm???



Thanks,
Krish. :cry:
0 votes
by (162k points)
I'm surprised you don't get an IOException immediately.

Try setting the timeout to say 1000 (milliseconds) - that should work.
0 votes
by (320 points)
Hi Bruce,

Thanks for ur reply.

Below is the code that i've used to do the FTP .

*********** ***********************************
package test;

import com.enterprisedt.net.ftp.FTPClient;
import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.FTPException;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class PutFile
{
FTPClient ftp = null;

BufferedReader reader = null;
int port = 21;

public PutFile(String hostName,String userName,String password)
{
reader = new BufferedReader(new InputStreamReader(System.in));
try
{
ftp = new FTPClient(hostName,port);
ftp.debugResponses(true);
ftp.login(userName,password);
ftp.setType(FTPTransferType.BINARY);
ftp.setTimeout(1000);
}

catch(IOException ex)
{
System.out.println("IO EXCPETION " + ex);
}
catch(Exception ex)
{
System.out.println("Exception in Constructor " +ex);
}
}

public static void main(String args[])
{
PutFile client = new PutFile(args[0],args[1],args[2]);
try
{
System.out.println("Enter the source file ");
String source = client.reader.readLine();
System.out.println("Enter the remote file name");
String dest = client.reader.readLine();

client.putFile(source,dest);
}
catch(Exception ex )
{
System.out.println("Exception in Main ---" + ex);
}

}

public boolean putFile(String source,String dest)
{
try
{
ftp.put(source,dest);

}
catch(FTPException ex )
{
System.out.println(" FTP Exception while putting file -->>" + ex.getReplyCode() +":: MESSSSSSS ::: "+ ex.getMessage());
ex.printStackTrace();
}
catch(Exception ex )
{
System.out.println("Exception in while putting file--" + ex);
}
return false;
}
}
******************************************************************************


I have set the Timeout to 1000 milliseconds...Here is the DEBUG Output of the above code.

It seems the setTimeout takes no effect.

OUTPUT :::
**************

DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 23 Jun 2006 20:52:25.848 : ---> PASV
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 23 Jun 2006 20:52:25.849 : 227 Entering Passive Mode (192,168,113,230,149,82)
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 23 Jun 2006 20:52:25.853 : ---> STOR My.zip
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 23 Jun 2006 20:52:25.921 : 150 Go ahead make my day^W^W^Wsend me the data.
DEBUG [com.enterprisedt.net.ftp.FTPClient] 23 Jun 2006 20:52:42.711 : Transferred 308839202 bytes to remote host
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 23 Jun 2006 20:52:42.713 : 226 File receive OK.

**********************************************************************************************************

Did i miss anything in the code .??. Appreciate your help .


Thanks,
Krish
0 votes
by (162k points)
It looks like the transfer succeeded? What's the problem?

The timeout of 1000 ms means if the connection is severed mid-transfer, within about 1000 ms you should get an IOException.



I have set the Timeout to 1000 milliseconds...Here is the DEBUG Output of the above code.

It seems the setTimeout takes no effect.

DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 23 Jun 2006 20:52:25.853 : ---> STOR My.zip
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 23 Jun 2006 20:52:25.921 : 150 Go ahead make my day^W^W^Wsend me the data.
DEBUG [com.enterprisedt.net.ftp.FTPClient] 23 Jun 2006 20:52:42.711 : Transferred 308839202 bytes to remote host
DEBUG [com.enterprisedt.net.ftp.FTPControlSocket] 23 Jun 2006 20:52:42.713 : 226 File receive OK.
0 votes
by (320 points)
Hi Bruce,

Thanks for your reply.Let me give the scenarios correctly,

Scenario 1:: (No timeout set , No network interruption )
---------------
Works fine.

Scenario 2 :: (Timeout Set ,No network interruption)
--------------
Time out takes no effect ..The output of this was given in my previous reply.

Scenario 3 :: (Timeout Set ,Netwok interruption (Network card unplugged while the transfer is going on) )
----------------
No exceptions thrown.

Scenario 4:: (No timeout set,Netwok interruption)
-----------------
No exceptions thrown.

As mentioned by you, exception should be thrown in the scenarios 2,3 and 4.

But the exceptions were never thrown and it looks like the transfer is paused.Once the connection is re-established the transfer also resumes....

I am using Mandriva Linux OS.

Appreciate your help ..


Cheers,
Krish
0 votes
by (162k points)
I wouldn't expect an exception in 1 or 2.

3 & 4 you should get an exception, it is pretty bizarre that you don't. What happens when command line FTP is interrupted?


Hi Bruce,

Thanks for your reply.Let me give the scenarios correctly,

Scenario 1:: (No timeout set , No network interruption )
---------------
Works fine.

Scenario 2 :: (Timeout Set ,No network interruption)
--------------
Time out takes no effect ..The output of this was given in my previous reply.

Scenario 3 :: (Timeout Set ,Netwok interruption (Network card unplugged while the transfer is going on) )
----------------
No exceptions thrown.

Scenario 4:: (No timeout set,Netwok interruption)
-----------------
No exceptions thrown.

As mentioned by you, exception should be thrown in the scenarios 2,3 and 4.

But the exceptions were never thrown and it looks like the transfer is paused.Once the connection is re-established the transfer also resumes....

I am using Mandriva Linux OS.

Appreciate your help ..


Cheers,
Krish
0 votes
by (320 points)
HI Bruce,

The same thing is happening with command line ftp TOO. :roll:
No exceptions thrown( Not sure whether exception will be thrown or not ) The transaction is paused and resumes if the connection re erstabilsed.
I have tried the command line ftp interruption with Mandrake and Red Hat Linux machines.

Thanks for your kind support.

Cheers,
Krish
0 votes
by (162k points)
That is pretty weird. There must be something strange about your network but I don't really have any idea what it is

HI Bruce,

The same thing is happening with command line ftp TOO. :roll:
No exceptions thrown( Not sure whether exception will be thrown or not ) The transaction is paused and resumes if the connection re erstabilsed.
I have tried the command line ftp interruption with Mandrake and Red Hat Linux machines.

Thanks for your kind support.

Cheers,
Krish

Categories

...