我想在没有 WINRM 的情况下将文件从本地服务器复制到远程服务器。远程服务器已获得凭据,并且不在本地网络或本地服务器的本地域中。请问你有解决办法吗?
I have this error:
MethodInvocationException: D:\powershell\ip.ps1:23:1
Line |
23 | $WebClient.DownloadFile($Source, $Dest)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request."
Here is my code:
$Source = "C:\test10\test10.txt"
$Dest = "\\public_ipadress_server\C:\test11\test10.txt"
$Username = "administrator"
$Password= convertto-securestring -AsPlainText -Force -String password
$MyIP = (Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
$MyIP | Out-File $Source
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password)
$WebClient.DownloadFile($Source, $Dest)