I am trying to sync a remote FTP folder to a local folder using Powershell. The remote FTP folder has a strange directory name that I am trying to exclude using a file mask. I have tried various combinations, but I am always getting the same error:
Error listing directory '/ftp_images/manufacturers/type=dir;sizd=4096;modify=20131010193915;UNIX.mode=0775;UNIX.uid=48;UNIX.gid=48;unique=14g1004d1;'.
Could not retrieve directory listing
Can't change directory to /ftp_images/manufacturers/type=dir;sizd=4096;modify=20131010193915;UNIX.mode=0775;UNIX.uid=48;UNIX.gid=48;unique=14g1004d1;/: No such file or directory
It would appear that WinSCP is trying to list the folder even though I have it excluded in my script and that is throwing the error. Does anyone know how to prevent WinSCP from even trying to list the folder or change to the directory?
Here's my code:
try
{
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Ftp
$sessionOptions.HostName = "HOST"
$sessionOptions.UserName = "USENAME"
$sessionOptions.Password = "PASSWORD"
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "| ftp_images/manufacturers/type=dir;;sizd=4096;;modify=20131010193915;;UNIX.mode=0775;;UNIX.uid=48;;UNIX.gid=48;;unique=14g1004d1;;/"
$session = New-Object WinSCP.Session
$session.SessionLogPath = "D:\winscp.log"
try
{
# Progress
$session.add_FileTransferred( { FileTransferred($_) } )
# Connect
$session.Open($sessionOptions)
#Sync
$synchronizationResult = $session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $destfilepath, $sourcefilepath, $False, $transferOptions)
# Throw on any error
$synchronizationResult.Check()
# Print results
foreach ($sync in $synchronizationResult.Transfers)
{
Write-Host ("Upload of {0} succeeded" -f $sync.FileName)
Write-Host "============================================"
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}
Any help would be appreciated. Thank you.