{"id":1081,"date":"2010-07-08T20:23:08","date_gmt":"2010-07-08T11:23:08","guid":{"rendered":"http:\/\/livedevil.net\/?p=1081"},"modified":"2010-07-08T20:23:08","modified_gmt":"2010-07-08T11:23:08","slug":"powershell-web-file-download-upload","status":"publish","type":"post","link":"https:\/\/talsu.net\/?p=1081","title":{"rendered":"Powershell &#8211; Web File Download , Upload"},"content":{"rendered":"<p>Powershell\uc744 \uc774\uc6a9\ud558\uc5ec Linux\uc758 wget\uacfc \uac19\uc774 Web (http, ftp) \uc5d0\uc11c File\uc744 \ub2e4\uc6b4\ub85c\ub4dc\ud558\uace0 \uc5c5\ub85c\ub4dc\ud558\ub294 \uc2a4\ud06c\ub9bd\ud2b8\ub97c \ub9cc\ub4e4\uc5b4 \ubcf4\uc790.<\/p>\n<p>.Net\uc758 WebClient\ub97c \uc0ac\uc6a9\ud558\uba74 \uac04\ub2e8\ud558\ub2e4.<\/p>\n<h2>Get-WebFile.ps1<\/h2>\n<pre class=\"lang:ps decode:true\">\nparam(\n\t[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]\n\t[String[]]$FileURLs,\n\t[String]$SavePath = (Get-Location),\n\t[String]$Username,\n\t[String]$Password\n)\n\nif ( -not (Test-Path $SavePath))\n{\n\treturn\n}\n\nforeach ($FileURL in $FileURLs)\n{\n\t$Pieces = $FileURL.Split(\"\/\")\n\t$FileName = $Pieces[$Pieces.Count - 1]\n\t$FilePath = Join-Path $SavePath $FileName\n\n\t$Client = New-Object System.Net.WebClient\n\n\tif (($Username -ne $null) -and ($Password -ne $null))\n\t{\n\t\t$Client.Credentials = New-Object System.Net.NetworkCredential($Username, $Password)\n\t}\n\n\tWrite-Host (\"[Download] {0} -> {1} ...\" -f $FileURL, $FilePath) -NoNewline\n\t$Client.DownloadFile($FileURL, $FilePath)\n\tWrite-Host \" Finish\"\n}\n<\/pre>\n<p>\ud575\uc2ec\uc740 WebClient \uac1c\uccb4\ub97c \ub9cc\ub4e4\uace0 DownloadFile \uba54\uc11c\ub4dc\ub97c \ud638\ucd9c \ud558\ub294 \uac83.<\/p>\n<p>Upload\ub3c4 \ub9c8\ucc2c\uac00\uc9c0\ub85c UploadFile \uba54\uc11c\ub4dc\ub97c \ud638\ucd9c \ud558\uba74 \ub41c\ub2e4.<\/p>\n<h2>Add-WebFile.ps1<\/h2>\n<pre class=\"lang:ps decode:true\">\nparam(\n    [Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]\n    [String[]]$Files,\n    [Parameter(Mandatory=$true, Position=1)]\n    [String]$TargetPath,\n    [String]$Username,\n    [String]$Password\n)\n\nforeach ($File in $Files)\n{\n    if (Test-Path $File)\n    {\n        $FileName = (Get-ChildItem $File).Name\n\t\tif ($TargetPath[$TargetPath.Length - 1] -ne \"\/\") { $TargetPath += \"\/\" }\n\n        $TargetFullPath = (\"{0}{1}\" -f $TargetPath, $FileName)\n        $Client = New-Object System.Net.WebClient\n\n        if (($Username -ne $null) -and ($Password -ne $null))\n        {\n            $Client.Credentials = New-Object System.Net.NetworkCredential($Username, $Password)\n        }\n        Write-Host (\"[Upload] {0} -> {1} ...\" -f $File, $TargetFullPath) -NoNewline\n        $Client.UploadFile($TargetFullPath, $File)\n        Write-Host \" Finish\"\n    }\n    else\n    {\n        Write-Host (\"Wrong File Path : {0}\" -f $File)\n    }\n}\n<\/pre>\n<p>\uc774\ub984 \uc815\ud558\uae30\uac00 \uae4c\ub2e4\ub86d\ub2e4. Get-Verb \uc548\uc5d0\uc11c \ub3d9\uc0ac\ub97c \uc120\ud0dd \ud558\ub294\ub370 Download, Upload \ub294 \uc5c6\uc73c\ubbc0\ub85c Get , Add\ub97c \uc0ac\uc6a9 \ud588\ub294\ub370 \uc801\uc808 \ud55c\uc9c0 \ubaa8\ub974\uaca0\ub2e4. Import, Export\ub3c4 \uace0\ub824 \ud574 \ubd24\uc9c0\ub9cc wget \uba85\ub839\uc774 \uc0dd\uac01 \ub098\uc11c Get\uc740 \uc4f0\uace0 \uc2f6\uc5c8\uace0, \uadf8\ub807\ub2e4\uace0 Upload\ub97c Set\uc73c\ub85c \ud558\ub294\uac83\ub3c4 \ub9c8\uc74c\uc5d0 \uc548\ub4e0\ub2e4. Update \uac00 \ub354 \uac00\uae4c\uc6b4 \uc758\ubbf8 \uc778\uac83 \uac19\uae30\ub3c4 \ud558\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Powershell\uc744 \uc774\uc6a9\ud558\uc5ec Linux\uc758 wget\uacfc \uac19\uc774 Web (http, ftp) \uc5d0\uc11c File\uc744 \ub2e4\uc6b4\ub85c\ub4dc\ud558\uace0 \uc5c5\ub85c\ub4dc\ud558\ub294 \uc2a4\ud06c\ub9bd\ud2b8\ub97c \ub9cc\ub4e4\uc5b4 \ubcf4\uc790. .Net\uc758 WebClient\ub97c \uc0ac\uc6a9\ud558\uba74 \uac04\ub2e8\ud558\ub2e4. Get-WebFile.ps1 param( [Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)] [String[]]$FileURLs, [String]$SavePath = (Get-Location), [String]$Username, [String]$Password ) if ( -not (Test-Path $SavePath)) { return } foreach ($FileURL in $FileURLs) { $Pieces = $FileURL.Split(&#8220;\/&#8221;) $FileName = $Pieces[$Pieces.Count &#8211; 1] $FilePath = Join-Path [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[26],"tags":[47,103,127,178,481,272,281,282,285,308,390,457],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pXV5a-hr","_links":{"self":[{"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/posts\/1081"}],"collection":[{"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1081"}],"version-history":[{"count":0,"href":"https:\/\/talsu.net\/index.php?rest_route=\/wp\/v2\/posts\/1081\/revisions"}],"wp:attachment":[{"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/talsu.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}