Re: GetFileToDirectory throws DirectoryNotFoundException
Indeed, the directory is NOT created. It was a mistake in the documentation. I've corrected it. Thanks.
Session.GetFileToDirectory
in PowerShell. According to the documentation the method creates the target directory if it doesn't exist. However when I try to copy the file to a directory that doesn't exist I get an error DirectoryNotFound
instead of it creating the directory.
Add-Type -Path "Path\to\the\assembly.dll"
$password = "xxxxxx"
$secpw = ConvertTo-SecureString -String $password -AsPlainText -Force
$fingerprint = "xxxx xxx xxxxx"
$sessionoptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
Hostname = "xxx.xxx.xxx.xxx"
Username = "xxxxx"
SecurePassword = $secpw
SshHostKeyFingerprint = $fingerprint
PortNumber = xxxxx
}
$session = New-Object WinSCP.Session
$session.Open($sessionoptions)
$session.GetFileToDirectory("/remote/path/to/file.zip", "C:\temp\folderthatdoesnotexist\", $false, $null)