session.FileExists not finding files
Hi,
I have to change an existing download process using a saved WinSCP session. I'm using a Powershell script to dynamically create a command file. The resulting command file is opening the saved WinSCP session.
The source directory to which I'm pulling files is /D:/bbsfiles/mucc.
I now need to check if the file at the source exists before download. Therefore I've changed the Powershell script to utilize the WinSCPnet.dll
As you can see I'm passing in the source directory, which would be "/D:/bbsfiles/mucc", etc. The protocol is FTP on port 21.
What I'm getting a failure on the first file stating that the file is not there. I manually FTP'd to the server to confirm that both the files are there.
I tried changing the source directory to just /bbsfiles/mucc, adding and removing quotes and nothing worked.
To test, I changed the script to connect to a different vendor. The protocol this time was FTPS on port 2010. The source for this connection was "/mucc/downloads". I was able to successfully download the files from this location.
I'm suspicious that it's the source location for the first vendor: /D:/bbsfiles/mucc
Any ideas?
I've tried WinSCPnet.dll for both WinSCP 5.7.5 and WinSCP 5.13
I have to change an existing download process using a saved WinSCP session. I'm using a Powershell script to dynamically create a command file. The resulting command file is opening the saved WinSCP session.
The source directory to which I'm pulling files is /D:/bbsfiles/mucc.
I now need to check if the file at the source exists before download. Therefore I've changed the Powershell script to utilize the WinSCPnet.dll
As you can see I'm passing in the source directory, which would be "/D:/bbsfiles/mucc", etc. The protocol is FTP on port 21.
What I'm getting a failure on the first file stating that the file is not there. I manually FTP'd to the server to confirm that both the files are there.
I tried changing the source directory to just /bbsfiles/mucc, adding and removing quotes and nothing worked.
To test, I changed the script to connect to a different vendor. The protocol this time was FTPS on port 2010. The source for this connection was "/mucc/downloads". I was able to successfully download the files from this location.
I'm suspicious that it's the source location for the first vendor: /D:/bbsfiles/mucc
Any ideas?
I've tried WinSCPnet.dll for both WinSCP 5.7.5 and WinSCP 5.13
param($SourceDir, $DestDir,$CurrentDate, $hostIP, $userId, $password, $protocol) try{ $date = [datetime]::ParseExact($currentDate,"yyyyMMdd",$null) $date = $date.AddDays(-1) $date = $date.ToString("MMdd") Write-Host "Date " $date Add-Type -Path "E:\Program Files\WinSCP 5.13\WinSCPnet.dll" $session = New-Object WinSCP.Session $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::$protocol HostName = $hostIP UserName = $userId Password = $password } try { $session.Open($sessionOptions) Write-Host $session.Opened $file1 = $SourceDir + "/M2MC" + $date + ".dat" $file2 = $SourceDir + "/M2MU" + $date + ".dat" $remotePath = $file1, $file2 Write-Host $remotePath foreach($path in $remotePath){ Write-Host "path " $path if ($session.FileExists($path)){ Write-Host "File $path exists." $transferResult = $session.GetFiles($path, "E:\temp\Shelley\test\", $False, $Null) Write-Host $transferResult foreach ($transfer in $transferResult.Transfers) { Write-Host "Download of $($transfer.FileName) succeeded" } }else{ Write-Host "File $path does not exist" exit 1 } } } finally{ $session.Dispose() } }catch{ Write-Host "Error: $($_.Exception.Message)" exit 2 }