Failed to execute SCP in SSH
Here I provide full details with script etails:
I am running my script in HUB1.
First, by asking users for credentials like username, password, filename, path.
Snipet example:
try:
usrname = raw_input('Enter your credentials:')
regex = r'[x][A-Za-z]{6,6}'
sigMatch = re.match(regex,usrname) --> username & pattern matching
sigMatch.group()
except AttributeError:
print "Kindly enter your name"
raise AttributeError
[...]
Immediately I do SSH from HUB1 like below:
ssh.load_system_host_keys()
ssh.connect('100.103.113.15', username='', password='')
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("cd /home/dir;ls -lrt")
By ssh from HUB1, I can actually log into HUB2 and copy the file to the desired directory [i, e, although I run my script in H1 via SSH, I can go through HUB2 and execute commands in H2 and perform the desired Operations]
Now the Challenge is gone:
Now I need to copy the same file from HUB2 to HUB3 [which I copied from Hub1] by running the same script in Hub1 as myself. So I did scp in SSH like below:
ssh_stdin,ssh_stdout, ssh_stderr = ssh.exec_command("scp %s
usrname@112.186.104.7:/home/dir/ABCdir" %(imageName))
Here you need to ask for a password for the user, for example . Enter your password , but above the command, the ssh_stderr query statement directs a pipe. Because of this, I cannot successfully copy the file when I scp in ssh.exec_command ("").
Points to remember:
-
I don't want to run two scripts one in H1 and the other in H2 (for scp) ---> excluded
-
My intention is to copy the file from h1 -> h2 -> h3, which are independent of each other.
I followed the following procedure and in addition to this I tried a couple of methods
-
adding unknown_host_key [by executing this input, output and error channels are open, but no file transfer occurs]
-
Calling another script in HUB2 [I can call scripts that don't require user input, but my goal is to give the user input. So it failed to call another script here].
I ask you to provide possible ways to eliminate the above problem.
source to share
No one has answered this question yet
Check out similar questions: