GetFileToDirectory throws DirectoryNotFoundException
I am trying to copy a specific file from an SFTP server to my PC using
Here's my stripped down code:
It wouldn't be hard to just create the directory first but since the documentation says that the method already does that I'm a bit confused why it's not working. Is it a permissions problem?
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.
Here's my stripped down code:
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)