0 votes
by (120 points)
edited

Hi,

Can i use SCP to copy files between two remote hosts. Sundar

1 Answer

0 votes
by (147k points)
edited

No, Rebex SCP control can only be used to copy files between the local host and remote host.

However, depending on your server OS and settings, you might be able to use Rebex SSH Shell for this purpose - connect to one of the remote hosts and run the 'scp' command there. First, connect using SSH shell client and make sure you can run "scp file.txt user02@server02:~/" succeessfully. Then, try the following sample code (C#)

// connect to the SSH server
Ssh ssh = new Ssh();
ssh.Connect("server01");
ssh.Login("user01", "password01");

// start a shell session in prompt mode
// (required for scp's password prompt to operate)
Shell shell = ssh.StartShell(ShellMode.Prompt);

// set shell prompt
// (see http://www.rebex.net/telnet.net/tutorial-telnet.aspx#using-shell for details)
shell.Prompt = "mask:user01@server01:*$ ";

// run 'scp' command to transfer a file to another server
shell.SendCommand("scp file.txt user02@server02:~/");

// read its response or 'Password: ' prompt
string result = shell.ReadAll("Password: ");
if (result.EndsWith("Password: "))
{
    // send the password
    shell.SendCommand("password02", true);
    result = shell.ReadAll();
}

// display the result
Console.WriteLine(result);

// close the shell and SSH connection
shell.Close();
ssh.Disconnect();

Of course, replace server01, server02, username01, etc. with the real values.

...