简体   繁体   English

暂停密码sftp bash脚本文件

[英]Pause for password sftp bash script file

I am trying to write a script to automatically upload files to a sftp server. 我正在尝试编写脚本以自动将文件上传到sftp服务器。 My problem is authentication. 我的问题是身份验证。

  • I know it is not possible to store a password in a bash script for sftp. 我知道不可能在sftp的bash脚本中存储密码。
  • I can't use keys because the admin of the server won't allow me. 我无法使用密钥,因为服务器的管理员不允许我使用。
  • I don't want to use any extras (sshpass/expect) because I can't guarantee they will be on the machine I'm using (the script are wanted so that the processes are not tied down to a particular machine). 我不想使用任何其他功能(sshpass / expect),因为我不能保证它们会出现在我正在使用的计算机上(需要脚本,以便将进程不绑定到特定的计算机上)。

Manual entry of the password is not a problem I just need to get the script to wait for the user to put the password in. At the minute when I run the script it opens terminal, prompts for the password, but when this is entered nothing else happens. 手动输入密码不是问题,我只需要获取脚本来等待用户输入密码即可。在运行脚本的那一刻,它会打开终端,提示输入密码,但是在没有输入密码的情况下否则发生。 If I enter the lines of code manual after it uploads everything correctly. 如果我在正确上传所有内容后输入了代码手册行。

#!bin/bash/
cd /remote_directory
lcd /local_directory
put some_file.txt

After months of looking for an answer I have finally found the solution. 经过几个月的寻找答案,我终于找到了解决方案。 It was in a comment on an answer in some other thread I can't even remember. 它是在我什至不记得的其他话题中对答案的评论。 Hope this can help others out there. 希望这可以帮助其他人。

Your bash script should look like this and will connect to the sftp server, prompt the user for the password, and then execute the remaining commands. 您的bash脚本应如下所示,并将连接到sftp服务器,提示用户输入密码,然后执行其余命令。

#!/bin/bash

sftp user@server <<!
cd /the/remote/directory
lcd /your/local/directory
put/get some.file
!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM