Directory contents are empty

Advertisement

cny
Joined:
Posts:
1

Directory contents are empty

Hi,

I'm using the standalone WinSCP with the .NET/Powershell extension in a powershell script. It works reasonably well, but there is sometimes a directory that WinSCP report as being empty (only consisting of ".."), when it is not.

Here is the example code I use:

. .\common.ps1
try
{
   Add-Type -Path "..\WinSCPnet.dll"
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
    $sessionOptions.HostName = "ftp.domain.com"
    $sessionOptions.UserName = "UserName"
    $sessionOptions.Password = "Password"
    $sessionOptions.SshHostKeyFingerprint = "ssh-dss 1024 asdfasdfasdfasdfasd random asdfasdfasdf"
   
   try
   {
      # Connect
      $session = New-Object WinSCP.Session
      $session.Open($sessionOptions)
      $directoryInfo = $session.ListDirectory("/remote/directory/path")
      $dirFiles = $directoryInfo.Files
      #$dirFiles would only contain ".." if I iterated over it
   }
   finally
   {
      # Disconnect, clean up
      $session.Dispose()
   }

    exit 0
}
catch [Exception]
{
    $_.Exception.Message | out-file $outputFp -encoding ascii -append
    exit 1
}

Curiously enough, when I ran most of this script by typing out lines (instead of running the script containing them), I think that directory's contents were shown to be correct. So I'm a little confused. Does anyone see any problem with the above code?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: Directory contents are empty

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate 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 may email it to me. You will find my address (if you log in) in my forum profile. Please include link back to this topic in your email. Also note in this topic that you have emailed the log.

Reply with quote

Advertisement

You can post new topics in this forum