Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
764 views
in Technique[技术] by (71.8m points)

windows - Using echo y as an automated response to a pcp hostkey prompt

I am building a batch file so that I can push firmware to 600 plus devices.

If I am at a command prompt I can run the following command on a single line that will push the firmware and answer yes to the SSH key prompt.

echo y | pscp -v -scp -pw password C:CNA1000FirmwareCNA1504v1.1.7CNA1504v1_1_7.run root@192.168.1.1:/tmp/.    

The echo y | answers yes to the SSH keys prompt. However when I try to add it to a batch file I get an error in the command prompt that it did not like the password.

Specifically, it looks like this;

Using username "root".
root@192.168.1.1's password:
Sent password
Access denied
Access denied

and then it repeats itself until I hit CTRL+C to break the batch file.

Is there a better way to do this so that I can automate the process?

Thanks,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I ended up using WinSCP.net for the batch file to correctly do what I was trying to do. Here is the example of how to do the above with WinSCP.net.

@echo off

"C:Program Files (x86)WinSCPWinSCP.com" ^
  /log="C:Program Files (x86)WinSCPWinSCP.log" /ini=nul ^
  /command ^
    "open scp://root:root@192.168.1.1/" ^
    "Put C:CNA1000FirmwareCNA1504v1.1.7CNA1504v1_1_7.run /tmp/."  ^
    "exit"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)

exit /b %WINSCP_RESULT%

And repeat for each IP address.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...