From 5ee0125046438556d1271e279d35700c1e765347 Mon Sep 17 00:00:00 2001 From: theli Date: Wed, 8 Mar 2006 16:34:05 +0000 Subject: [PATCH] *) adding possibility to configure the server port for seed uploading via scp. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1861 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/yacy/seedUpload/yacySeedUploadScp.html | 5 +++ .../yacy/seedUpload/yacySeedUploadScp.java | 41 ++++++++++++++----- yacy.init | 1 + 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/htroot/yacy/seedUpload/yacySeedUploadScp.html b/htroot/yacy/seedUpload/yacySeedUploadScp.html index 4b726075b..e1bc9c7f3 100644 --- a/htroot/yacy/seedUpload/yacySeedUploadScp.html +++ b/htroot/yacy/seedUpload/yacySeedUploadScp.html @@ -7,6 +7,11 @@ The host where you have an account, like 'my.host.net' + + Server Port: + + The sshd port of the host, like '22' + Path: diff --git a/source/de/anomic/yacy/seedUpload/yacySeedUploadScp.java b/source/de/anomic/yacy/seedUpload/yacySeedUploadScp.java index 22b00d1ac..333f3d7fa 100644 --- a/source/de/anomic/yacy/seedUpload/yacySeedUploadScp.java +++ b/source/de/anomic/yacy/seedUpload/yacySeedUploadScp.java @@ -66,6 +66,7 @@ import de.anomic.yacy.yacySeedUploader; public class yacySeedUploadScp implements yacySeedUploader { public static final String CONFIG_SCP_SERVER = "seedScpServer"; + public static final String CONFIG_SCP_SERVER_PORT = "seedScpServerPort"; public static final String CONFIG_SCP_ACCOUNT = "seedScpAccount"; public static final String CONFIG_SCP_PASSWORD = "seedScpPassword"; public static final String CONFIG_SCP_PATH = "seedScpPath"; @@ -77,23 +78,36 @@ public class yacySeedUploadScp implements yacySeedUploader { if ((seedFile == null)||(!seedFile.exists())) throw new Exception("Seed file does not exist."); String seedScpServer = sb.getConfig(CONFIG_SCP_SERVER,null); + String seedScpServerPort = sb.getConfig(CONFIG_SCP_SERVER_PORT,"22"); String seedScpAccount = sb.getConfig(CONFIG_SCP_ACCOUNT,null); String seedScpPassword = sb.getConfig(CONFIG_SCP_PASSWORD,null); String seedScpPath = sb.getConfig(CONFIG_SCP_PATH,null); - if ((seedScpServer != null) && (seedScpAccount != null) && (seedScpPassword != null) && (seedScpPath != null)) { - return sshc.put(seedScpServer, seedFile, seedScpPath, seedScpAccount, seedScpPassword); - } - return "Seed upload settings not configured properly. password-len=" + - seedScpPassword.length() + ", filePath=" + - seedScpPath; + if (seedScpServer == null || seedScpServer.length() == 0) + throw new Exception("Seed SCP upload settings not configured properly. Servername must not be null or empty."); + else if (seedScpAccount == null || seedScpAccount.length() == 0) + throw new Exception("Seed SCP upload settings not configured properly. Username must not be null or empty."); + else if (seedScpPassword == null || seedScpPassword.length() == 0) + throw new Exception("Seed SCP upload settings not configured properly. Password must not be null or empty."); + else if (seedScpPath == null || seedScpPath.length() == 0) + throw new Exception("Seed SCP upload settings not configured properly. File path must not be null or empty."); + else if (seedScpServerPort == null || seedScpServerPort.length() == 0) + throw new Exception("Seed SCP upload settings not configured properly. Server port must not be null or empty."); + int port = 22; + try { + port = Integer.valueOf(seedScpServerPort).intValue(); + } catch (NumberFormatException ex) { + throw new Exception("Seed SCP upload settings not configured properly. Server port is not a vaild integer."); + } + + return sshc.put(seedScpServer, port, seedFile, seedScpPath, seedScpAccount, seedScpPassword); } catch (Exception e) { throw e; } } public String[] getConfigurationOptions() { - return new String[] {CONFIG_SCP_SERVER,CONFIG_SCP_ACCOUNT,CONFIG_SCP_PASSWORD,CONFIG_SCP_PATH}; + return new String[] {CONFIG_SCP_SERVER,CONFIG_SCP_SERVER_PORT,CONFIG_SCP_ACCOUNT,CONFIG_SCP_PASSWORD,CONFIG_SCP_PATH}; } public String[] getLibxDependencies() { @@ -103,9 +117,14 @@ public class yacySeedUploadScp implements yacySeedUploader { } class sshc { - public static String put(String host, - File localFile, String remoteName, - String account, String password) throws Exception { + public static String put( + String host, + int port, + File localFile, + String remoteName, + String account, + String password + ) throws Exception { Session session = null; try { @@ -113,7 +132,7 @@ class sshc { JSch jsch=new JSch(); // setting hostname, username, userpassword - session = jsch.getSession(account, host, 22); + session = jsch.getSession(account, host, port); session.setPassword(password); /* diff --git a/yacy.init b/yacy.init index 022d01be3..9d7f71ecd 100644 --- a/yacy.init +++ b/yacy.init @@ -280,6 +280,7 @@ seedFilePath= # Please note that this upload method can only be used if you have installed # this optional upload method. seedScpServer= +seedScpServerPort= seedScpAccount= seedScpPassword= seedScpPath=