WMI remote process to copy file

后端 未结 2 792
星月不相逢
星月不相逢 2020-12-06 15:01

Long story short, my application needs to copy a file to a remote target where UNC connections TO the target might not be possible. However UNC connections FROM the target a

相关标签:
2条回答
  • 2020-12-06 15:36

    For security reasons, most methods of programatically connecting to a remote machine and telling it to copy a file to itself from another machine are blocked. One thing that finally worked for me is FTP. Using the above code I can do something like this:

    InputParameters("CommandLine") = "ftp -s:c:\ftpscript.txt"
    

    Which causes the ftp commandline utility to run on the remote machine, using c:\ftpscript.txt to get a list of commands from. Since there is no way to copy the ftp script file to the target (again, no UNC connection), I can first do:

    InputParameters("CommandLine") = "cmd /c echo myFTPCommands > c:\ftpscript.txt"
    

    And this works :)

    UPDATE: Never thought to use XCOPY and it works perfectly:

    InputParameters("CommandLine") = "cmd /c echo F | xcopy remotefile localfile"
    

    UPDATE: XCOPY worked yesterday, now it doesn't. NOTHING has changed, so I am at a complete loss for explanation.

    0 讨论(0)
  • 2020-12-06 15:38

    Frank you should actually give yourself credit since the method you created is likely the first ever to get around WMI limitations of remote file copy! I did 3 weeks of searching for info/workaround and yours is the only one that works! If I had any points I would vote for your solution...

    I created a fully working VBS & WMI script based on your method:

     InputParameters("CommandLine") = "cmd /c echo myFTPCommands > c:\ftpscript.txt"
    

    where you replace myFTPCommands as needed with whatever script you want to go into the file c:\ftpscript.bat (or .vbs, .ps1, or whatever you like). If you couldn't fit enough text in the one-line script, then append with the same method using >>. Now, you can use XCOPY, PSEXEC, COPY, or anything else to run the script you just created on the remote host's file system.

    Here's my fully fleshed out VBScript using your method. Thanks again. :)

    HTH, Lizz

    0 讨论(0)
提交回复
热议问题