View Javadoc

1   package fr.in2p3.jsaga.adaptor.data;
2   
3   import java.io.EOFException;
4   import java.io.IOException;
5   
6   import org.apache.log4j.Logger;
7   import org.globus.ftp.GridFTPClient;
8   import org.globus.ftp.exception.ServerException;
9   import org.globus.ftp.vanilla.BasicClientControlChannel;
10  
11  /* ***************************************************
12   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
13   * ***             http://cc.in2p3.fr/             ***
14   * ***************************************************
15   * File:   GsiftpClient
16   * Author: Lionel Schwarz (lionel.schwarz@in2p3.fr)
17   * Date:   13 dec 2011
18   * ***************************************************
19   * Description:                                      */
20  /**
21   * This class uses the local FTPControlChannel class instead of Globus GridFTPControlChannel to get the welcome message
22   */
23  
24  public class GsiftpClient extends GridFTPClient {
25  	private static Logger logger = Logger.getLogger(GsiftpClient.class);
26  	public String welcomeMessage = null;
27  	public GsiftpClient(String host, int port) throws IOException,
28  			ServerException {
29  		super(host, port);
30  
31  		welcomeMessage = getLastReply().getMessage();
32  		// disable maxWait=600s otherwise transfers stop after 600s ...
33  		this.session.maxWait = BasicClientControlChannel.WAIT_FOREVER;
34  	}
35  
36  	public String getWelcome() {
37  		return this.welcomeMessage;
38  	}
39  	
40  	public boolean isAppendSupported() {
41  		// Some servers do not support 'append' flag at PUT
42  		// the 'APPE' will simply overwrite the file without any error
43  		// Known servers are those with welcome message containing "[VDT patched x.x.x]"
44  		if (this.getWelcome().contains("[VDT patched")) {
45  			return false;
46  		}
47  		return true;
48  	}
49  	
50  	@Override
51  	public void close() throws ServerException, IOException {
52  		// Do not close
53  	}
54  	
55  	public void disconnect() throws ServerException, IOException {
56  		try{
57  			super.close();
58  		} catch(EOFException e){
59  			//Already closed ?
60  			logger.warn("The GSIFTP connection seems already closed: " + e.getMessage());
61  		} catch (ServerException se) {
62              logger.warn(se.getCustomMessage());
63  		}
64  	}
65  }