通过 SSH 备份 Bash 文件

发布于 2024-12-19 14:50:31 字数 463 浏览 3 评论 0原文

我正在尝试制作一个 bash 脚本,它将文件从我的机器传输到由我的学校维护的用于备份代码的服务器。每次要传输文件都需要手动传输,很麻烦。

某些应用程序(例如 TextWrangler)能够保存到服务器。但是,我宁愿能够从终端快速完成此操作。

我该去哪里?我是否需要以某种方式传递我想作为参数发送的文件?有没有办法确保它进入正确的目录?

#!/bin/bash
# This should log me into orca
# http://aruljohn.com/info/filetransfer/
# http://stackoverflow.com/questions/1895185/how-to-ssh-from-within-a-bash-script
sftp username@place
expect "username@place password: "
sleep 1
send "mypassword"

I am trying to make a bash script that will transfer a file from my machine to a server maintained by my school that is used to back up code. It is a hassle to transfer the file manually every single time that I want to make the transfer.

Some applications, like TextWrangler, have the ability to save to server. However, I would rather be able to do it quickly from terminal.

Where would I go from here? Would I need to somehow pass in the file I'd like to send as a parameter? Is there a way to make sure that it goes to the correct directory?

#!/bin/bash
# This should log me into orca
# http://aruljohn.com/info/filetransfer/
# http://stackoverflow.com/questions/1895185/how-to-ssh-from-within-a-bash-script
sftp username@place
expect "username@place password: "
sleep 1
send "mypassword"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

腹黑女流氓 2024-12-26 14:50:31

为什么不使用“scp”安全复制而不是 sftp。

您不需要“期望”来运行它,并且,如果正确配置远程/本地证书,您将不需要弄乱密码。

查看一些示例,了解它是多么简单。以及完整的如何文档。

Why not use "scp" secure copy instead of sftp.

You don't need "expect" to run this, and, if you configure the remote/local certificates properly you will not need to mess with passwords.

See some examples of how simple it can be. And the full how to docs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文