Skip to content

Commit 79ebab4

Browse files
committed
Added more variables
1 parent 6610021 commit 79ebab4

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

Copy-AWS.psm1

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
function Copy-AWS
33
{
44
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)]
109
[Alias('FullName')]
1110
[string[]]$Source,
1211

13-
[Parameter(
14-
Position=1,
15-
Mandatory=$True)]
12+
[Parameter(Position=1,
13+
Mandatory=$True)]
1614
[string]$Destination,
1715

1816
[Parameter(Mandatory=$False)]
@@ -22,20 +20,29 @@ function Copy-AWS
2220

2321
begin{
2422
$pscp="C:\Program Files (x86)\PuTTY\pscp.exe"
25-
$root=Get-Root -Path (pwd)
23+
$root=Get-Root -FolderName .pscp
2624
if($root)
2725
{
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+
3132
}
3233

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"
3340

3441
if($Recurse){$r="-r"}
3542
}
3643

3744
process {
38-
if($aws_info)
45+
if($info)
3946
{
4047
foreach($path in $source)
4148
{
@@ -44,16 +51,16 @@ function Copy-AWS
4451
if(!(Test-Path -Path $Destination) -and ($Destination -match "/"))
4552
{
4653
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"
4855
}
4956
else
5057
{
5158
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"
5360
}
5461

5562
Write-Verbose $command
56-
Invoke-Expression $command
63+
#Invoke-Expression $command
5764
}
5865
}
5966

@@ -107,8 +114,18 @@ http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter5.html
107114
}
108115

109116

110-
function Get-Root([string] $CurrentPath, [string]$FolderName)
117+
function Get-Root
111118
{
119+
param(
120+
[Parameter(Position=0,
121+
Mandatory=$True)]
122+
[string]$FolderName,
123+
124+
[Parameter(
125+
Mandatory=$False)]
126+
[string]$CurrentPath="."
127+
)
128+
112129
$CurrentPath=Resolve-Path $CurrentPath
113130
Write-Verbose "Current path is: $CurrentPath"
114131

@@ -127,8 +144,11 @@ function Get-Root([string] $CurrentPath, [string]$FolderName)
127144

128145
$CurrentPath=([System.IO.Directory]::GetParent(($CurrentPath))).FullName
129146
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+
#>
132152
}
133153

134154
Write-Host "Imported Copy-AWS"

Example/.pscp/aws_info.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

Example/.pscp/pscp_info.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
keyfile=
2+
user=1102205
3+
password=rsp1102205
4+
address=cae

Example/test.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)