2
2
function Copy-AWS
3
3
{
4
4
param (
5
- [Parameter (
6
- Position = 0 ,
7
- Mandatory = $True ,
8
- ValueFromPipeline = $true ,
9
- ValueFromPipelineByPropertyName = $true )]
5
+ [Parameter (Position = 0 ,
6
+ Mandatory = $True ,
7
+ ValueFromPipeline = $true ,
8
+ ValueFromPipelineByPropertyName = $true )]
10
9
[Alias (' FullName' )]
11
10
[string []]$Source ,
12
11
13
- [Parameter (
14
- Position = 1 ,
15
- Mandatory = $True )]
12
+ [Parameter (Position = 1 ,
13
+ Mandatory = $True )]
16
14
[string ]$Destination ,
17
15
18
16
[Parameter (Mandatory = $False )]
@@ -22,20 +20,29 @@ function Copy-AWS
22
20
23
21
begin {
24
22
$pscp = " C:\Program Files (x86)\PuTTY\pscp.exe"
25
- $root = Get-Root - Path (pwd)
23
+ $root = Get-Root - FolderName .pscp
26
24
if ($root )
27
25
{
28
- $aws_info = Get-Content - Path " $root \aws_info.txt" | ConvertFrom-StringData
29
- $keypath = " $root \$ ( $aws_info.keyfile ) "
30
- $host = $aws_info.host
26
+ $info = (Get-Content - Path " $root \pscp_info.txt" ) -join " `r`n " | ConvertFrom-StringData
27
+ $keypath = if ($info.keyfile ){" -i $root \$ ( $info.keyfile ) " }
28
+ $user = $info.user
29
+ $password = if ($info.password ){" -pw $ ( $info.password ) " }
30
+ $_address = $info.address
31
+
31
32
}
32
33
34
+ Write-Verbose " pscp: $pscp "
35
+ Write-Verbose " root: $root "
36
+ Write-Verbose " keypath: $keypath "
37
+ Write-Verbose " user: $user "
38
+ Write-Verbose " password: $password "
39
+ Write-Verbose " address: $_address "
33
40
34
41
if ($Recurse ){$r = " -r" }
35
42
}
36
43
37
44
process {
38
- if ($aws_info )
45
+ if ($info )
39
46
{
40
47
foreach ($path in $source )
41
48
{
@@ -44,16 +51,16 @@ function Copy-AWS
44
51
if (! (Test-Path - Path $Destination ) -and ($Destination -match " /" ))
45
52
{
46
53
Write-Verbose " remote destination"
47
- $command = " & `" $pscp `" $r -i $keypath $path ec2- user@$host : $destination "
54
+ $command = " & `" $pscp `" $r $keypath $password $ path $ user @$_address : $destination "
48
55
}
49
56
else
50
57
{
51
58
Write-Verbose " local destination"
52
- $command = " & `" $pscp `" $r -i $keypath ec2- user@$host :$path $destination "
59
+ $command = " & `" $pscp `" $r $keypath $password $ user @$_address :$path $destination "
53
60
}
54
61
55
62
Write-Verbose $command
56
- Invoke-Expression $command
63
+ # Invoke-Expression $command
57
64
}
58
65
}
59
66
@@ -107,8 +114,18 @@ http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter5.html
107
114
}
108
115
109
116
110
- function Get-Root ([ string ] $CurrentPath , [ string ] $FolderName )
117
+ function Get-Root
111
118
{
119
+ param (
120
+ [Parameter (Position = 0 ,
121
+ Mandatory = $True )]
122
+ [string ]$FolderName ,
123
+
124
+ [Parameter (
125
+ Mandatory = $False )]
126
+ [string ]$CurrentPath = " ."
127
+ )
128
+
112
129
$CurrentPath = Resolve-Path $CurrentPath
113
130
Write-Verbose " Current path is: $CurrentPath "
114
131
@@ -127,8 +144,11 @@ function Get-Root([string] $CurrentPath, [string]$FolderName)
127
144
128
145
$CurrentPath = ([System.IO.Directory ]::GetParent(($CurrentPath ))).FullName
129
146
Write-Verbose " Change current to parent: $CurrentPath "
130
- Get-Root $CurrentPath $FolderName
131
-
147
+ Get-Root - FolderName $FolderName - CurrentPath $CurrentPath
148
+ <#
149
+ . SYNOPSIS
150
+ Gets the path to a specified folder in the parent hierarchy of the current path.
151
+ #>
132
152
}
133
153
134
154
Write-Host " Imported Copy-AWS"
0 commit comments