001: //yacySeedUploadFtp.java
002: //-------------------------------------
003: //part of YACY
004: //(C) by Michael Peter Christen; mc@anomic.de
005: //first published on http://www.anomic.de
006: //Frankfurt, Germany, 2004
007: //
008: //This file ist contributed by Martin Thelian
009: //last major change: $LastChangedDate: 2006-01-23 15:08:39 +0000 (Mo, 23 Jan 2006) $ by $LastChangedBy: rramthun $
010: //Revision: $LastChangedRevision: 1417 $
011: //
012: //This program is free software; you can redistribute it and/or modify
013: //it under the terms of the GNU General Public License as published by
014: //the Free Software Foundation; either version 2 of the License, or
015: //(at your option) any later version.
016: //
017: //This program is distributed in the hope that it will be useful,
018: //but WITHOUT ANY WARRANTY; without even the implied warranty of
019: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: //GNU General Public License for more details.
021: //
022: //You should have received a copy of the GNU General Public License
023: //along with this program; if not, write to the Free Software
024: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
025: //
026: //Using this software in any meaning (reading, learning, copying, compiling,
027: //running) means that you agree that the Author(s) is (are) not responsible
028: //for cost, loss of data or any harm that may be caused directly or indirectly
029: //by usage of this softare or this documentation. The usage of this software
030: //is on your own risk. The installation and usage (starting/running) of this
031: //software may allow other people or application to access your computer and
032: //any attached devices and is highly dependent on the configuration of the
033: //software which must be done by the user of the software; the author(s) is
034: //(are) also not responsible for proper configuration and usage of the
035: //software, even if provoked by documentation provided together with
036: //the software.
037: //
038: //Any changes to this file according to the GPL as documented in the file
039: //gpl.txt aside this file in the shipment you received can be done to the
040: //lines that follows this copyright notice here, but changes must not be
041: //done inside the copyright notive above. A re-distribution must contain
042: //the intact and unchanged copyright notice.
043: //Contributions and changes to the program code must be marked as such.
044:
045: package de.anomic.yacy.seedUpload;
046:
047: import java.io.File;
048:
049: import de.anomic.net.ftpc;
050: import de.anomic.server.serverSwitch;
051: import de.anomic.yacy.yacySeedDB;
052: import de.anomic.yacy.yacySeedUploader;
053:
054: public class yacySeedUploadFtp implements yacySeedUploader {
055:
056: public static final String CONFIG_FTP_SERVER = "seedFTPServer";
057: public static final String CONFIG_FTP_ACCOUNT = "seedFTPAccount";
058: public static final String CONFIG_FTP_PASSWORD = "seedFTPPassword";
059: public static final String CONFIG_FTP_PATH = "seedFTPPath";
060:
061: public String uploadSeedFile(serverSwitch sb, yacySeedDB seedDB,
062: File seedFile) throws Exception {
063: try {
064: if (sb == null)
065: throw new NullPointerException(
066: "Reference to serverSwitch must not be null.");
067: if (seedDB == null)
068: throw new NullPointerException(
069: "Reference to seedDB must not be null.");
070: if ((seedFile == null) || (!seedFile.exists()))
071: throw new Exception("Seed file does not exist.");
072: if (!seedFile.isFile())
073: throw new Exception("Seed file is not a file.");
074: if (!seedFile.canRead())
075: throw new Exception("Seed file is not readable.");
076:
077: String seedFTPServer = sb
078: .getConfig(CONFIG_FTP_SERVER, null);
079: String seedFTPAccount = sb.getConfig(CONFIG_FTP_ACCOUNT,
080: null);
081: String seedFTPPassword = sb.getConfig(CONFIG_FTP_PASSWORD,
082: null);
083: File seedFTPPath = new File(sb.getConfig(CONFIG_FTP_PATH,
084: null));
085:
086: if ((seedFTPServer != null) && (seedFTPAccount != null)
087: && (seedFTPPassword != null)
088: && (seedFTPPath != null)) {
089: String log = ftpc.put(seedFTPServer, seedFile,
090: seedFTPPath.getParent(), seedFTPPath.getName(),
091: seedFTPAccount, seedFTPPassword);
092: return log;
093: }
094: throw new Exception(
095: "Seed upload settings not configured properly. password-len="
096: + seedFTPPassword.length() + ", filePath="
097: + seedFTPPath);
098: } catch (Exception e) {
099: throw e;
100: }
101: }
102:
103: public String[] getConfigurationOptions() {
104: return new String[] { CONFIG_FTP_SERVER, CONFIG_FTP_ACCOUNT,
105: CONFIG_FTP_PASSWORD, CONFIG_FTP_PATH };
106: }
107:
108: public String[] getLibxDependencies() {
109: return new String[] {};
110: }
111:
112: }
|