【发布时间】:2014-01-15 09:42:38
【问题描述】:
我需要创建一种方法来传达命令并将文件从主机服务器传输到开发板。
- 对板的唯一访问是通过主机服务器(有线以太网连接)。
- 主机服务器和主板都运行 Linux。
- 我有能力改变板上的 Linux 环境。
- 我没有能力更改主机服务器环境。
- 我不知道哪些用户需要连接到开发板。
- 主机服务器和主板之间的连接不需要是安全的。
现在,我正在使用 netcat 来满足我的需求,但遇到了可靠性问题 - 有人可以指点我一些更适合我的需求并且性能更高的工具吗?
我目前的解决方案:
一个脚本不断在板上运行:
while [ 1 ] ; do
# Start a netcat server, awaiting a file.
nc -l -p 1357 > file.bin
# Acknowledge receipt of file.
status=fail
while [ ${status} -ne 0 ] ; do
status=$(echo 0 | nc <host_ip> 2468 2>&1)
done
# Wait for a command.
nc -l -p 1357 -e /bin/sh
# Acknowledge receipt of command.
status=fail
while [ ${status} -ne 0 ] ; do
status=$(echo 0 | nc <host ip> 2468 2>&1)
done
done
用户访问该板的唯一方法是通过服务器上的脚本:
# Send over a file.
cat some_file.bin | /bin/nc -w 10
# Wait for acknowledge.
if [ $( nc -l 2468 ) -ne 0 ] ; then
exit # Fail
fi
# Send a command.
echo "<some_command>" | nc -w 10 <board ip> 1357
# Wait for acknowledge.
if [ $( nc -l 2468 ) -ne 0 ] ; then
exit # Fail
fi
我现在使用 netcat 的原因是我不知道在没有密码的情况下使用 SSH 或 SCP 的任何方法:
- 我无法为需要访问开发板的每个人生成 SSH 密钥,尤其是因为我不知道谁会使用它。
- 我无法安装 sshpass 或期望,因为我无法控制服务器。
请帮忙, 谢谢。
【问题讨论】:
标签: linux bash network-protocols netcat