Hi,
I too realized this problem and had a closer look at the implementation.
As for my understanding of RFC959 page.30/31, the implementation of the abort()
command is incorrect because it does not deal with the fact that two concurrent
commands could be running the same time (RETR vs. ABOR).
The first reply code send by the FTP Server is always the reply code for the
aborted command (RETR and not ABOR). This must be, because while sending the
ABOR command, the original command could finish.
So the first reply code is always for the original command, but (in current
implementation) is fetched from the ABOR command.
I tried the following implementation of abort() which is a modified version of
the FTP.sendCommand() implementation without calling getReply():
public boolean abort() throws IOException
{
String message;
_controlOutput.write(message = FTPCommand._commands[FTPCommand.ABOR] +
SocketClient.NETASCII_EOL);
_controlOutput.flush();
if (_commandSupport_.getListenerCount() > 0)
_commandSupport_.fireCommandSent(FTPCommand._commands[FTPCommand.ABOR],
message);
return true;
}
This allows the original command to fetch it's reply code, but leaves the reply
code for the ABOR command which must be fetched manually before sending the
next FTP command.
I hope this helps finding a proper solution.
Kind regards,
Martin
-----Ursprüngliche Nachricht-----
Von: Ghislain Gadbois [mailto:[EMAIL PROTECTED]
Gesendet: Montag, 13. März 2006 20:29
An: [email protected]
Betreff: [Net]: FTPClient.abort problem
Hi,
I'm using Jakarta Commons Net's FTPClient to do FTP transfers. I use version
1.4.1 on J2SDK 1.4.2_11.
I'm trying to abort an FTP transfer in a separate thread.
What happens is:
1- The thread that is downloading the file is not interrupted so the file is
all downloaded
2- Since the download thread is not interrupted, the responses are not handled
properly:
* The thread that is calling abort() gets a 426 - transfer aborted response
* The thread that is downloading the file get 226 ABOR command succesful
Following this message is a sample program to reproduce the problem and a
sample of this program's output...
Is there something that I'm doing wrong?
What would be required to solve the problem?
Thanks a lot for your help!
Ghis
---------- Sample code -------------
import java.io.FileOutputStream;
import org.apache.commons.net.ProtocolCommandEvent;
import org.apache.commons.net.ProtocolCommandListener;
import org.apache.commons.net.ftp.FTPClient;
public class TestsNetCommons
{
public static void main(String[] pasArgs)
{
final Object oMonitor = new Object();
FTPClient oFtp = null;
Thread oThread;
ProtocolCommandListener oListener = new ProtocolCommandListener()
{
public void protocolCommandSent(ProtocolCommandEvent poEvent)
{
String sMessage;
sMessage = poEvent.getMessage();
if(sMessage != null)
{
sMessage = sMessage.trim();
}
// Remove the password from the log files...
if(sMessage.startsWith("PASS "))
{
sMessage = sMessage.substring(0, 5) + "*****";
}
System.out.println("Client: " + sMessage);
}
public void protocolReplyReceived(ProtocolCommandEvent poEvent)
{
String sMessage;
sMessage = poEvent.getMessage();
if(sMessage != null)
{
sMessage = sMessage.trim();
}
System.out.println("Server: " + sMessage);
}
};
try
{
oFtp = new FTPClient();
oFtp.addProtocolCommandListener(oListener);
oFtp.connect("127.0.0.1");
if(oFtp.login("ftptest", "ftptest"))
{
final FTPClient oFtpClient = oFtp;
// Thread used to download a file...
oThread = new Thread()
{
public void run()
{
FileOutputStream oOut = null;
try
{
oOut = new FileOutputStream("C:\\bigfile.zip");
oFtpClient.retrieveFile("bigfile.zip", oOut);
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
if(oOut != null)
{
try
{
oOut.close();
}
catch(Exception ex)
{
// Don't care...
}
}
}
} // run };
oThread.start();
// Wait a little, then abort the transfer...
Thread.currentThread().sleep(1000);
oFtp.abort();
// Wait for the download thread to finish it's job
oThread.join();
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
if(oFtp != null)
{
try
{
oFtp.logout();
oFtp.disconnect();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
}
}
------------- Sample output --------------------
Server: 220 localhost Microsoft FTP Service (Version 5.0).
Client: USER ftptest
Server: 331 Password required for ftptest.
Client: PASS *****
Server: 230 User ftptest logged in.
Client: PORT 127,0,0,1,10,174
Server: 200 PORT command successful.
Client: RETR bigfile.zip
Server: 150 Opening ASCII mode data connection for bigfile.zip(29716750 bytes).
Client: ABOR
Server: 426 Connection closed; transfer aborted.
Server: 226 ABOR command successful.
Client: QUIT
Server: 221
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]