powershellsftplswinscpstat

WinSCP stat command says FileNotFound, but it exists when I do ls


When I run this in PowerShell where $File is just "/path/to/FileName.csv"

& "C:\Program Files (x86)\WinSCP\WinSCP.com" /command "open sftp://username:password@server/" "stat $File" "exit"

I get:

Can't get attributes of file "/path/to/FileName.csv" No such file or directory. Error code: 2 Error message from server (en): FileNotFound: The supplied file does not exist.

But if I do a list command, I see the file that I'm trying to stat. The path and file name matches up and is case sensitive.

& "C:\Program Files (x86)\WinSCP\WinSCP.com" /command "open sftp://username:password@server/" "ls /path/to/FileName.csv" "exit"

Why is stat not able to see that my file exists?


Solution

  • I just switched from using the stat command to WinSCP's .NET assembly and using $session.ListDirectory($File) instead.

    Thanks everyone for your input and patience.