Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,18 @@ $RECYCLE.BIN/
# ==========
# Data files
# ==========
*.cro
*.cro

# ================
# Encryption Files
# ================

# Credential files
*.key

# ============
# Module Files
# ============

# Manifiest files
/Modules/*/*.psd1
42 changes: 42 additions & 0 deletions Modules/File.Transfer/File.Transfer.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Get functions and types to import
$scriptsToConfigure = @(Get-ChildItem -Path $PSScriptRoot -File -Filter "*.ps1" -ErrorAction SilentlyContinue)
$classesToImport = @( Get-ChildItem -Path $PSScriptRoot\Classes -File -Filter "*.cs" -ErrorAction SilentlyContinue | Sort-Object Name )
$privateFunctionsToImport = @( Get-ChildItem -Path $PSScriptRoot\Private -File -Filter "*.ps1" -ErrorAction SilentlyContinue | Sort-Object Name )
$publicFunctionsToImport = @( Get-ChildItem -Path $PSScriptRoot\Public -File -Filter "*.ps1" -ErrorAction SilentlyContinue | Sort-Object Name )
$scriptsToImport = $privateFunctionsToImport + $publicFunctionsToImport

# Special Module's configurations
foreach ($script in $scriptsToConfigure) {
try {
if($script.BaseName -eq $script.Directory.Name)
{ & $script.FullName }
}
catch {
Write-Warning -Message "Failed to configure the module with $($script.FullName) script: $_"
return
}
}

# Add types based on C# Classes
foreach ($class in $classesToImport) {
try {
$classType = Get-Content -Path $class.FullName -Raw
Add-Type -TypeDefinition $classType
}
catch {
Write-Error -Message "Failed to import the class $($class.FullName): $_"
return
}
}

# Import functions
foreach ($function in $scriptsToImport) {
try { . $function.FullName }
catch {
Write-Error -Message "Failed to import the script $($function.FullName): $_"
return
}
}

# Export public functions
Export-ModuleMember -Function $publicFunctionsToImport.BaseName
51 changes: 51 additions & 0 deletions Modules/File.Transfer/Public/New-FileTransfer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function New-FileTransfer {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[String]
$OriginPath,
[Parameter(Mandatory)]
[String]
$DestinationPath,
[Parameter(Mandatory)]
[String]
$FileNameToCopy
)

if ($null -ne $OriginPath){
$originPath = (Get-Item -Path $OriginPath).FullName
}

if ($null -ne $DestinationPath){
$destinationPath = (Get-Item -Path $DestinationPath).FullName
}

if ($null -ne $FileToCopy){
$fileNameToCopy = (Get-Item -Path $FileNameToCopy).FullName
}

$credential = Get-Credential
$originSVR = New-PSDrive -Name "OriginSVR" -Root $originPath -PSProvider "FileSystem" -Credential $credential
$fileToCopy = Get-ChildItem -Path $originSVR.Root | Where-Object {$_.Name -eq $fileNameToCopy}

try {
Copy-Item -Path $fileToCopy.FullName -Destination $destinationPath

$fileInDestination = Get-ChildItem -Path $destinationPath | Where-Object {$_.Name -eq $fileToCopy.Name}

[String] $originFileHash = (Get-FileHash -Path $fileToCopy.FullName -ErrorAction SilentlyContinue).Hash
[String] $destinationFileHash = (Get-FileHash -Path $fileInDestination.FullName -ErrorAction SilentlyContinue).Hash

if ($originFileHash -eq $destinationFileHash) {
Write-Host "OK, the integrity is correct"
}
else {
[String] $differentHashError = ("[ERROR] - File integrity error: {0}" -f $DestinationFile)
Write-Error -Message $differentHashError -ErrorAction Stop
}
}
# Catch the error when the file is being used
catch [Microsoft.PowerShell.Commands.WriteErrorException] {
Write-Host "Error, the file es being used"
}
}
4 changes: 2 additions & 2 deletions Modules/Template/Template.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ foreach ($class in $classesToImport) {
Add-Type -TypeDefinition $classType
}
catch {
Write-Warning -Message "Failed to import the class $($class.FullName): $_"
Write-Error -Message "Failed to import the class $($class.FullName): $_"
return
}
}
Expand All @@ -33,7 +33,7 @@ foreach ($class in $classesToImport) {
foreach ($function in $scriptsToImport) {
try { . $function.FullName }
catch {
Write-Warning -Message "Failed to import the script $($function.FullName): $_"
Write-Error -Message "Failed to import the script $($function.FullName): $_"
return
}
}
Expand Down