01: /*
02: * ChainBuilder ESB
03: * Visual Enterprise Integration
04: *
05: * Copyright (C) 2006 Bostech Corporation
06: *
07: * This program is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU General Public License as published by
09: * the Free Software Foundation; either version 2 of the License, or
10: * (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307
20: * USA
21: *
22: *
23: * $Id: Connect.java 11093 2007-12-21 18:22:22Z mpreston $
24: */
25: package com.bostechcorp.cbesb.runtime.ftp.interpreter;
26:
27: import java.io.IOException;
28: import java.net.SocketException;
29: import java.util.HashMap;
30: import java.util.Map;
31:
32: import org.apache.commons.logging.Log;
33: import org.apache.commons.logging.LogFactory;
34: import org.apache.commons.net.ftp.FTPClient;
35:
36: /**
37: * Opens a connection to an FTP server.
38: *
39: * @author j.zhang
40: * @version 1.0.0
41: */
42: public class Connect extends AbstractCommandExpression {
43:
44: protected final transient Log logger = LogFactory
45: .getLog(getClass());
46:
47: /**
48: * Hostname of FTP server, if not supplied ftpHost setting is used from Output configuration.
49: */
50: public static final String HOST = "host";
51:
52: /**
53: * Port number to connect to. If not specified, default FTP port is used.
54: */
55: public static final String PORT = "port";
56:
57: /**
58: * The Map of parameters.
59: */
60: private Map paramMap = new HashMap<String, String>();
61:
62: @Override
63: /* (non-Javadoc)
64: * @see com.bostechcorp.cbesb.runtime.ftp.AbstractCommandExpression#interpret(java.util.Map)
65: */
66: public void interpret(Map<String, String> paramMap) {
67: this .paramMap = paramMap;
68: }
69:
70: @Override
71: /* (non-Javadoc)
72: * @see com.bostechcorp.cbesb.runtime.ftp.AbstractCommandExpression#execute(org.apache.commons.net.ftp.FTPClient)
73: */
74: public Object execute(FtpExecContext context) {
75: FTPClient ftp = context.getFtpclient();
76: logger.debug("connect:");
77: String host = (String) paramMap.get(HOST);
78: String port = (String) paramMap.get(PORT);
79: logger.debug(" host: " + host);
80: logger.debug(" port: " + port);
81: try {
82: if (port == null || "".equals(port)) {
83: ftp.connect(host);
84: } else {
85: ftp.connect(host, Integer.parseInt(port));
86: }
87: } catch (NumberFormatException nfe) {
88: // nfe.printStackTrace();
89: return nfe;
90: } catch (SocketException se) {
91: // se.printStackTrace();
92: return se;
93: } catch (IOException ioe) {
94: // ioe.printStackTrace();
95: return ioe;
96: }
97: return true;
98: }
99: }
|