Session.GetFileToDirectory Not creating local directory if it doesn't exist

Advertisement

Tegy
Guest

Session.GetFileToDirectory Not creating local directory if it doesn't exist

I'm trying to pull files to my local machine like so:
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)
}
Everything works fine if I already have the directory created on my local machine but if it doesn't exist, I get:
Exception 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 might be wrong as I am fairly new to PowerShell but It says on the documentation
If the target local directory does not exist, it is created.
I must be missing something. Thanks in advance for any light shed on this.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
36,736
Location:
Prague, Czechia

Re: Session.GetFileToDirectory Not creating local directory if it doesn't exist

Thanks for your report. Indeed, the documentation is wrong. I've removed that statement.

Reply with quote

Advertisement

You can post new topics in this forum