<p>Hi! I've written a small library that makes possible to upload and download files by SSH connection (on top of golang/x/crypto/ssh) and cat utility on the SSH server. There are already some libraries that solve the same problem, but they are built on running scp utility on the SSH server. I've had read man page for cat, manually tested the lib and it seems that is a legit approach to using cat. Is there someone experienced in Unix here, who can kindly clarify if cat can modify or skip the bytes from/to file or not (I believe it's not by design). Also, I appreciate if someone provides some code review. Here is the link to the lib: <a href="https://github.com/mosolovsa/go_cat_sshfilerw" rel="nofollow">https://github.com/mosolovsa/go_cat_sshfilerw</a></p>
<hr/>**评论:**<br/><br/>Creshal: <pre><p>Why cat on the remote end instead of sftp or rsync?</p></pre>mosolov: <pre><p>I have electronic boards with embedded linux. There is no sftp or rsync daemon. However there is option to use scp for file transmitting, but it's need to be compiled (which must be not too complicated).</p></pre>Creshal: <pre><p>Okay, that's fair, and scp is pretty limited in capabilities too. </p>
<p>If you want range skipping capabilities, have a look at <code>dd</code> and its <code>seek</code>/<code>skip</code> parameters. </p></pre>mosolov: <pre><p>Actually, I'm in reverse situation. I'm curious about does "cat" utility able to implicitly change the file content, when streaming it to stdout or when streaming from stdin to file.
Thanks for help!</p></pre>Creshal: <pre><p>cat by itself doesn't change anything, actually. It only opens files read only. "cat > foo" copies from stdin to stdout and then your <em>shell</em> writes that to foo.</p></pre>cdoxsey: <pre><p>You can use head or tail:</p>
<pre><code>† echo 'hello world' | head -c 5
hello
† echo 'hello world' | tail -c +6
world
</code></pre></pre>shazow: <pre><p>Have you considered doing something like:</p>
<p>$ cat localfile | ssh myserver "cat > remotefile"</p>
<p>Can also do the reverse.</p></pre>mosolov: <pre><p>Yes, that will do the trick. But I need also to add some logic, e.g. send a file with an update (tar.gz), then send a command to unpack it and preferably without visible user and pass for SSH.
That's mostly the pet project to get on with golang.
The goal was to make simple writing an app, that would be able to send the commands from list that I permit, download/upload files that I permit and forbid anything else.
Thanks for help!</p></pre>shazow: <pre><p>+1 to pet projects, keep at it! :)</p></pre>cosiner_z: <pre><p>Maybe you can give a try to <a href="https://github.com/cosiner/socker" rel="nofollow">https://github.com/cosiner/socker</a>.</p></pre>mosolov: <pre><p>That library looks like flexible, mature and flexible solution. However, it's using sftp form file upload/download and exactly in my case I don't has an SFTP server on my target boards.</p></pre>cosiner_z: <pre><p>As far as i known, SFTP has no daemon, it's a protocol running over ssh and enabled by default in openssh.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传