Skip to content

Commit

Permalink
*) adding possibility to configure the server port for seed uploading…
Browse files Browse the repository at this point in the history
… via scp.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1861 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
theli committed Mar 8, 2006
1 parent 2065138 commit 5ee0125
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
5 changes: 5 additions & 0 deletions htroot/yacy/seedUpload/yacySeedUploadScp.html
Expand Up @@ -7,6 +7,11 @@
<td><input name="seedScpServer" type="text" size="40" value="#[seedScpServer]#"></td>
<td><i>The host where you have an account, like 'my.host.net'</i></td>
</tr>
<tr valign="top">
<td>Server&nbsp;Port:</td>
<td><input name="seedScpServerPort" type="text" size="40" value="#[seedScpServerPort]#"></td>
<td><i>The sshd port of the host, like '22'</i></td>
</tr>
<tr valign="top">
<td>Path:</td>
<td><input name="seedScpPath" type="text" size="40" value="#[seedScpPath]#"></td>
Expand Down
41 changes: 30 additions & 11 deletions source/de/anomic/yacy/seedUpload/yacySeedUploadScp.java
Expand Up @@ -66,6 +66,7 @@
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";
Expand All @@ -77,23 +78,36 @@ public String uploadSeedFile(serverSwitch sb, yacySeedDB seedDB, File seedFile)
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() {
Expand All @@ -103,17 +117,22 @@ public String[] getLibxDependencies() {
}

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 {
// Creating a new secure channel object
JSch jsch=new JSch();

// setting hostname, username, userpassword
session = jsch.getSession(account, host, 22);
session = jsch.getSession(account, host, port);
session.setPassword(password);

/*
Expand Down
1 change: 1 addition & 0 deletions yacy.init
Expand Up @@ -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=
Expand Down

0 comments on commit 5ee0125

Please sign in to comment.