通过 SSH 备份 Bash 文件
我正在尝试制作一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不使用“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.