WMI remote process to copy file

后端 未结 2 802
星月不相逢
星月不相逢 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.

提交回复
热议问题