Package org.metricshub.winrm
Class ShellFileCopy
java.lang.Object
org.metricshub.winrm.ShellFileCopy
Copies local files to the remote host through the WinRM command shell itself, without SMB.
Each file is base64-encoded locally, appended to a remote temporary file with chunked
echo commands, decoded with certutil -decode, and verified by comparing a
remote certutil -hashfile digest with the locally computed one. The transfer rides
the already-authenticated (and, over HTTP, encrypted) WinRM channel: no extra TCP port,
no separate authentication, no dependency.
A file that is already present on the remote host with an identical digest is not transferred again, so repeatedly executing the same script is cheap.
This transport is intended for the small script files that
WinRMCommandExecutor copies before execution; base64
over SOAP is not suited to bulk data.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcopyLocalFilesToRemote(WindowsRemoteExecutor windowsRemoteExecutor, String command, List<String> localFiles, long timeout) Copy the specified local files to a temporary directory on the remote host through the WinRM command shell, and return the command updated so that each reference to a local file path points to the corresponding remote copy.static voidcopyLocalFileToRemoteFile(WindowsRemoteExecutor windowsRemoteExecutor, Path localPath, String remoteFile, long timeout) Copy one local file to an explicit path on the remote host through the WinRM command shell, creating the destination directory when needed.
-
Method Details
-
copyLocalFilesToRemote
public static String copyLocalFilesToRemote(WindowsRemoteExecutor windowsRemoteExecutor, String command, List<String> localFiles, long timeout) throws IOException, TimeoutException, WindowsRemoteException Copy the specified local files to a temporary directory on the remote host through the WinRM command shell, and return the command updated so that each reference to a local file path points to the corresponding remote copy.- Parameters:
windowsRemoteExecutor- Executor connected to the remote host (mandatory)command- The command referencing the local files (mandatory)localFiles- The list of local files to copy (may be null or empty: no-op)timeout- Timeout in milliseconds (throws an IllegalArgumentException if negative or zero)- Returns:
- The command updated with the remote paths of the copied files
- Throws:
IOException- If a local file cannot be readTimeoutException- To notify userName of timeoutWindowsRemoteException- For any problem encountered on the remote host
-
copyLocalFileToRemoteFile
public static void copyLocalFileToRemoteFile(WindowsRemoteExecutor windowsRemoteExecutor, Path localPath, String remoteFile, long timeout) throws IOException, TimeoutException, WindowsRemoteException Copy one local file to an explicit path on the remote host through the WinRM command shell, creating the destination directory when needed. The transfer is digest-verified, and skipped entirely when the destination already carries the digest of the local file.- Parameters:
windowsRemoteExecutor- Executor connected to the remote host (mandatory)localPath- The local file to copy (mandatory)remoteFile- The absolute destination path on the remote host, e.g.C:\Windows\Temp\collect.ps1(mandatory)timeout- Timeout in milliseconds (throws an IllegalArgumentException if negative or zero)- Throws:
IOException- If the local file cannot be readTimeoutException- To notify userName of timeoutWindowsRemoteException- For any problem encountered on the remote host
-