【问题标题】:Write a Script to respond to prompts with specified text编写脚本以使用指定文本响应提示
【发布时间】:2023-04-01 22:34:01
【问题描述】:

我正在编写一个脚本,它会在脚本运行时自动捕获屏幕截图并触发 iSight 拍摄静态照片,然后将其上传到 FTP。除了一件事之外,一切都很完美,我的 FTP 需要在提示时输入用户名和密码(在捕获两个图像之后)

这就是我所拥有的:

echo “GOLDENEYE ACTIVATED….”
screencapture -x screen.jpg
imagesnap Mugshot.jpg
ftp <YourServerHere>

终端响应:

Connected to <YourServerHere>

现在,出现此信息时必须输入用户名:

220 Welcome to <ServerDomain>, FTP server standing by ...
Name (<ServerName>.<DomainName>.:<Name>): <Type UserName Here - Hit Enter>

并且,成功输入有效用户名后将输入密码:

331 Hello <UserName>, your FTP account password is required:
Password: <Type Your Password Here - Hit Enter>

输入正确的凭据后,终端将响应:

230-Login successful, your current directory is /
230 0 Kbytes used (0%) - authorized: 7340032 Kb
Remote system type is UNIX.
Using binary mode to transfer files.

还有,上传图片:

ftp> put /Mugshot.jpeg

ftp> put /Screen.jpeg

我正在尝试在给出提示后自动输入用户名和密码,以使脚本成功

文本将是“用户名”和“密码”,在给出每个提示后输入。

我对终端和脚本完全陌生,只是在业余时间玩,请原谅这里的任何不正确之处,感谢任何帮助和教育!

【问题讨论】:

  • 您可能正在寻找expect

标签: macos unix ftp terminal prompt


【解决方案1】:

一般的解决方案是expect command

但对于你的任务来说,这有点过头了。


ftp 从标准输入读取命令。

那就这样吧:

ftp -n < command.txt

-n 可防止自动提示输入用户名/密码。我们使用下面的user 命令明确地提供这些。

commands.txt 文件如下所示:

open host
user user password
put /path
bye

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-29
    • 2014-08-09
    • 2016-08-08
    • 1970-01-01
    • 2016-09-04
    • 2011-09-04
    相关资源
    最近更新 更多