Powershell script to Upload log file from local system to http URL

依然范特西╮ 提交于 2019-12-21 17:27:26

问题


How could i upload a log file from my local system to a webpage (http://abc..) using powershell script? Thanks in advance


回答1:


If you are using HTTP, try something like this:

    $sourceFilePath = "c:\MyLocalFolder\LocalLogFileName.log"
    $siteAddress = "http://192.168.15.12/DestinationFolder"
    $urlDest = "{0}/{1}" -f ($siteAddress, "DestinationLogFileName.log";
    $webClient = New-Object System.Net.WebClient;
    $webClient.Credentials = New-Object System.Net.NetworkCredential("MyUserName", "MyPassword");
    ("*** Uploading {0} file to {1} ***" -f ($sourceFilePath, $siteAddress) ) | write-host -ForegroundColor Green -BackgroundColor Yellow
    $webClient.UploadFile($urlDest, "PUT", $sourceFilePath);


来源:https://stackoverflow.com/questions/25356228/powershell-script-to-upload-log-file-from-local-system-to-http-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!