■ 넥서스 저장소(Nexus Repository)에 파일을 업로드하는 방법을 보여준다.
▶ 실행 명령
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
$CustomWebClientSource = @" using System.Net; public class CustomWebClient : WebClient { public int Timeout; public CustomWebClient() { Timeout = 600000; } protected override WebRequest GetWebRequest(System.Uri uri) { WebRequest request = base.GetWebRequest(uri); if(request != null) { request.Timeout = Timeout; } return request; } } "@; Add-Type -TypeDefinition $CustomWebClientSource -Language CSharp function UploadFile { [CmdletBinding()] Param ( [Parameter(Position = 0, Mandatory = $True)] [string]$SourceFilePath, [Parameter(Position = 1, Mandatory = $True)] [string]$TargetURI, [Parameter(Position = 2, Mandatory = $True)] [string]$UserID, [Parameter(Position = 3, Mandatory = $True)] [string]$Password ) BEGIN { $WebClient = New-Object CustomWebClient $Credentials = New-Object System.Net.NetworkCredential $Credentials.UserName = $UserID $Credentials.Password = $Password $WebClient.Credentials = $Credentials } PROCESS { $WebClient.UploadFile($TagetURI, 'PUT', $SourceFilePath) } END { $WebClient.Dispose() } } UploadFile -SourceFilePath 'd:/test.txt' -TargetURI 'http://nexus.net/repository/arca/test.txt' -UserID 'king' -Password 'password' |