download/upload files via SSH+cat

blov · · 610 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi! I&#39;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&#39;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&#39;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&#39;s need to be compiled (which must be not too complicated).</p></pre>Creshal: <pre><p>Okay, that&#39;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&#39;m in reverse situation. I&#39;m curious about does &#34;cat&#34; 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&#39;t change anything, actually. It only opens files read only. &#34;cat &gt; foo&#34; 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 &#39;hello world&#39; | head -c 5 hello † echo &#39;hello world&#39; | tail -c +6 world </code></pre></pre>shazow: <pre><p>Have you considered doing something like:</p> <p>$ cat localfile | ssh myserver &#34;cat &gt; remotefile&#34;</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&#39;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&#39;s using sftp form file upload/download and exactly in my case I don&#39;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&#39;s a protocol running over ssh and enabled by default in openssh.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

610 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传