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've implemented the solution:
psexec embedded in executable by go-bindata. Before calling psexec - restore psexec in the folder with executable from memory.
Creating shared resource with psexec (sysinternal utility for remote command invocation on windows host) running "net share ..." on the remote host.
Authenticate by syscall WNetAddConnection2W on the created shared resource.
Perform copy operations.
Delete shared resource on the remote host by psexec.
Delete psexec form executable folder.
It's working but it's very ugly and disgusting solution. I would appreciate any advices. I didn't found any libraries providing this functionality. It seems C# has a framework, but I don't want any external dependencies (.NET framework).
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't want to let customer know login and password (ofcourse it's pretty easy to track winapi call and it's params, but I don'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's own binary protocol that provide possibility to copy and write files to the embedded system, but I want to provide tool, that doesn't depend on the main software. So if it's not working I can get the dump to analyse it, and, possibly, write update through this way with a little upgrade.
评论:
tgulacsi:
ericzhill:Write a little web server which accepts file uploads into that directory. Or use rsync.
Hexodam:net use \target\c$ /user...
copy \target\c$\path\file c:\path\file
net use \target\c$ /d
vldo:Use the right tool for the job
Here the right tool is either one of the old native solutions or powershell. Go with powershell, learn it, love it. Seriosly.
Whenever I am asked what languages someone should learn I always recommend Go, Python and Powershell.
jamra06:Go with powershell, learn it, love it. Seriosly.
I second this, use the right tool for the job. For more details: Calling WNetAddConnection2 from PowerShell
jeffrallen: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.
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'd be set. But it doesn'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't tear it all out and make it depend on stuff you have a legit need to not depend on.)
-jeff
