如何在sftp模式下在shell脚本中添加确认 [英] How to add confirm in shell script in sftp mode

查看:119
本文介绍了如何在sftp模式下在shell脚本中添加确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 shell 脚本,它正在执行一些重命名和归档步骤.我添加了 sftp 命令来复制多个文件.但是,当我尝试通过 Putty 登录到远程计算机时,它会要求确认,例如 您确定要继续连接吗(是/否)?.我需要输入是.但由于这是通过脚本完成的,我不知道该怎么做.下面是我正在使用的脚本

I have a shell script which is performing some renaming and archiving steps. I have added sftp commands to copy multiple files. But when i try to login to the remote machine thru putty it asks for confirmation like Are you sure you want to continue connecting (yes/no)? . I need to enter yes. but since this is being done thru the script am not sure how to do it. below is the script i am using

cd <File Source Location>
sftp user1@remoteserver
sftp> cd <target location to be copied>
sftp> mput *.gz 

quit

如何在执行sftp user1@remoteserver后在上面的代码中传递yes.

how to i pass yes in the above code after sftp user1@remoteserver is executed.

非常感谢任何帮助.

推荐答案

我认为您正在尝试解决错误的问题.

I think that you are trying to solve the wrong problem.

sftp 要求您确认,因为它还不知道主机的密钥.因此,您需要像这样将其添加到 known_hosts 文件中

sftp asks you for confirmation because it does not know the key of the host yet. Therefore you need to add it to you known_hosts file like this

ssh-keyscan -H remoteserver >> ~/.ssh/known_hosts

我建议使用 scp 命令而不是 sftp 因为它可以一步完成你想要的一切.

I recommend using scp command instead of sftp as it will do all you want in one step.

scp somewhere/*.gz user1@remoteserver:somewhere/else

<小时>

如果出于某种原因您不想这样做.您可能会考虑一个非常不安全的命令

sftp -o StrictHostKeyChecking=no user1@remoteserver

通过使用上述命令,您很容易受到中间人攻击,您已收到警告.

这篇关于如何在sftp模式下在shell脚本中添加确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆