Issue
I am building a job in jenkins in which i need to copy the folders and file from jenkins server to another server. The server has port 802 and password= "PASSWORD" how to copy folder to another server?
sshpass -p'PASSWORD'scp -P 802 $SSH_OPTS -r $WORKSPACE/target/abc.war root@2xx.xx.xxx.xx:/root/war/
Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
-f filename Take password to use from file
-d number Use number as file descriptor for getting password
-p password Provide password as argument (security unwise)
-e Password is passed as env-var "SSHPASS"
With no parameters - password will be taken from stdin
-P prompt Which string should sshpass search for to detect a password prompt
-v Be verbose about what you're doing
-h Show help (this screen)
-V Print version information
At most one of -f, -d, -p or -e should be used
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Solution
The best way to do this is using expect script, you can use the below code:
!/usr/bin/expect -f
Usage sshsudologin.expect (host) (ssh user) (ssh password)
set timeout 10
spawn scp -r "/folder_to_copy/" [lindex $argv 1]@[lindex $argv 0]:"destination_dir/"
expect "*?assword" { send "[lindex $argv 2]\r" }
expect eof
Answered By - piyush sachdeva Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.