session.FileExists not finding files

Advertisement

rsford31
Joined:
Posts:
32

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

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
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: session.FileExists not finding files

This still looks like the same problem we are discussing already in a separate thread:
https://winscp.net/forum/viewtopic.php?t=26414

Make sure you have a file name case right. If that does not help, please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

rsford31
Joined:
Posts:
32

Re: session.FileExists not finding files

martin wrote:

This still looks like the same problem we are discussing already in a separate thread:
https://winscp.net/forum/viewtopic.php?t=26414

Make sure you have a file name case right. If that does not help, please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.
Hi Martin,
Your assistance with my other post lead me to resolve this as well. It was in fact due to the name case not matching what was at the source.
Thanks so much!

Reply with quote

Advertisement

You can post new topics in this forum