Session.GetFileToDirectory Not creating local directory if it doesn't exist
I'm trying to pull files to my local machine like so:
Everything works fine if I already have the directory created on my local machine but if it doesn't exist, I get:
foreach ($fileInfo in $Files){ Write-Host "Downloading $($fileInfo.FullName) ..." $filePath = [WinSCP.RemotePath]::EscapeFileMask($fileInfo.FullName) $FileFullNameBS = $fileInfo.FullName.Replace("/", "\") $sp = Split-Path -Path $FileFullNameBS $LocalDirectory = "$($localPath)$($sp)" $session.GetFileToDirectory($filePath, $LocalDirectory, $false) }
I might be wrong as I am fairly new to PowerShell but It says on the documentationException calling "GetFileToDirectory" with "3" argument(s): Local Directory
At localfilepath\txtmerge.ps1:69 char:5
+ $session.GetFileToDirectory($filePath, $LocalDirectory, $false)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DirectoryNotFoundException
I must be missing something. Thanks in advance for any light shed on this.If the target local directory does not exist, it is created.