Golang and windows shared resource creation

agolangf · · 486 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have a task to copy files from the specified folder on the remote windows host. I have administrator login and password to the remote host. I&#39;ve implemented the solution:</p> <ol> <li><p>psexec embedded in executable by go-bindata. Before calling psexec - restore psexec in the folder with executable from memory.</p></li> <li><p>Creating shared resource with psexec (sysinternal utility for remote command invocation on windows host) running &#34;net share ...&#34; on the remote host.</p></li> <li><p>Authenticate by syscall WNetAddConnection2W on the created shared resource.</p></li> <li><p>Perform copy operations.</p></li> <li><p>Delete shared resource on the remote host by psexec.</p></li> <li><p>Delete psexec form executable folder.</p></li> </ol> <p>It&#39;s working but it&#39;s very ugly and disgusting solution. I would appreciate any advices. I didn&#39;t found any libraries providing this functionality. It seems C# has a framework, but I don&#39;t want any external dependencies (.NET framework).</p> <p><a href="https://gist.github.com/mosolovsa/ccd463775bd772433f749b7897950478" rel="nofollow">Rough cut concept proof</a></p> <p>EDIT: Thanks for answers. To be more specific I need to say that the task is to provide the tool for dumping embedded system software (embedded system with Windows CE on board). Theare are plenty of devices already working on site. There are no rsync or SSH server on it. I don&#39;t want to let customer know login and password (ofcourse it&#39;s pretty easy to track winapi call and it&#39;s params, but I don&#39;t really think that somebody would go for it) so the Powershell is not what I want. Web server seems to me like an overkill, besides the main software has it&#39;s own binary protocol that provide possibility to copy and write files to the embedded system, but I want to provide tool, that doesn&#39;t depend on the main software. So if it&#39;s not working I can get the dump to analyse it, and, possibly, write update through this way with a little upgrade.</p> <hr/>**评论:**<br/><br/>tgulacsi: <pre><p>Write a little web server which accepts file uploads into that directory. Or use rsync.</p></pre>ericzhill: <pre><p>net use \\target\c$ /user...</p> <p>copy \\target\c$\path\file c:\path\file</p> <p>net use \\target\c$ /d</p></pre>Hexodam: <pre><p>Use the right tool for the job</p> <p>Here the right tool is either one of the old native solutions or powershell. Go with powershell, learn it, love it. Seriosly.</p> <p>Whenever I am asked what languages someone should learn I always recommend Go, Python and Powershell.</p></pre>vldo: <pre><blockquote> <p>Go with powershell, learn it, love it. Seriosly.</p> </blockquote> <p>I second this, use the right tool for the job. For more details: <a href="http://stackoverflow.com/questions/1477328/calling-wnetaddconnection2-from-powershell" rel="nofollow">Calling WNetAddConnection2 from PowerShell</a></p></pre>jamra06: <pre><p>I just set up a CI web deploy on windows server. It uses WinRM. Maybe that will do the job for you. Or you. I would try to use powershell tools to do something like this over go. The only downside is you may need to CI figure the server to allow remote connections.</p></pre>jeffrallen: <pre><p>Your solution is ugly and disgusting because you are setting a difficult task for yourself, not wanting dependencies. If your target machine had Cygwin and OpenSSH and rsync on it, you&#39;d be set. But it doesn&#39;t and you are doing a service to the next guy to come behind you by keeping all the mess in one place that cleans up after itself, so I say go for it. (Just make sure that the docs explain WHY it is ugly and messy, so that the next guy appreciates it and doesn&#39;t tear it all out and make it depend on stuff you have a legit need to not depend on.)</p> <p>-jeff</p></pre>

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

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