PowerShell script does not recognize path

Advertisement

sleepersimulant
Joined:
Posts:
6
Location:
Switzerland

PowerShell script does not recognize path

Hello dear forum

I have written a PowerShell script which should automatically open the saved session and copy files from the source to the destination (Windows to Linux). New files are to be copied or revised, as the script will run every minute.

The connection can be established but then I get the error message:
Compare ...
Local “remote” <= remote station “testfolder
Error displaying the directory “remote\*.*”.
Error retrieving the file list for “remote\*.*”.
What could be the cause? I can see the folder via the WinSCP GUI and the files in it are listed.

The script was tested in PowerShell ISE
$winscpPath = "C:\Program Files (x86)\WinSCP\WinSCP.com"
$sessionName = "testuser"
$sourcePath = "C:\Users\test user\Documents\Test" 
$destinationPath = "/testfolder"
 
$scriptPath = [System.IO.Path]::GetTempFileName()
@"
open $sessionName
lcd "$sourcePath"
cd "$destinationPath"
synchronize -criteria=either -filemask="*>=1D" local remote
exit
"@ | Set-Content -Path $scriptPath
 
& $winscpPath /script="$scriptPath"
Remove-Item $scriptPath

Reply with quote

Advertisement

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

Re: Powershell script does not recognize path

The local remote shouldn't be there.
Either you want:
lcd "$sourcePath"
cd "$destinationPath"
synchronize -criteria=either -filemask="*>=1D"
or
synchronize -criteria=either -filemask="*>=1D" "$sourcePath" "$destinationPath"

Reply with quote

sleepersimulant
Joined:
Posts:
6
Location:
Switzerland

Thanks a lot!
I have now taken your input and tested this and get the following output back:

Searching for host...
Connecting to host...
Authenticating...
Using username "testuser".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] testuser
C:\Users\testuser\Documents\Test
/testfolder/test
Unknown option 'C:\Users\testuser\Documents\Test'.

Reply with quote

martin
Site Admin
martin avatar

Which of my two suggestions have you taken? What does your current code look line? What does the generated script file look like?

Reply with quote

sleepersimulant
Joined:
Posts:
6
Location:
Switzerland

Hello martin!

Thanks for your reply and time.

I have tested both variants.
The first variant:
$winscpPath = "C:\Program Files (x86)\WinSCP\WinSCP.com"
$sessionName = "testuser"
$sourcePath = "C:\Users\test user\Documents\Test" 
$destinationPath = "/testfolder"
 
$scriptPath = [System.IO.Path]::GetTempFileName()
@"
open $sessionName
lcd "$sourcePath"
cd "$destinationPath"
synchronize -criteria=either -filemask="*>=1D" "$sourcePath" "$destinationPath"
exit
"@ | Set-Content -Path $scriptPath
 
& $winscpPath /script="$scriptPath"
Remove-Item $scriptPath
Output in ISE:
Aktive Sitzung: [1] testuser
C:\Users\testuser\Documents\Test
/testfolder
Unbekannte Option „C:\Users\testuser\Documents\Test“.
(translated: unknown option C:\PATH)
Second variant:
$winscpPath = "C:\Program Files (x86)\WinSCP\WinSCP.com"
$sessionName = "testuser"
$sourcePath = "C:\Users\test user\Documents\Test" 
$destinationPath = "/testfolder"
 
$scriptPath = [System.IO.Path]::GetTempFileName()
@"
open $sessionName
lcd "$sourcePath"
cd "$destinationPath"
synchronize -criteria=either -filemask="*>=1D"
exit
"@ | Set-Content -Path $scriptPath
 
& $winscpPath /script="$scriptPath"
Remove-Item $scriptPath
Output:
Aktive Sitzung: [1] testuser
C:\Users\testuser\Documents\Test
/testfolder/test
Parameter für Befehl „synchronize“ fehlt.
(translated: Parameter for synchronization missing)

Reply with quote

Advertisement

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

Sorry, I've misunderstood your code.
So the synchronize command needs to include the direction parameter – local or remote or both. Like this:
synchronize -criteria=either -filemask="*>=1D" local "$sourcePath" "$destinationPath"

Reply with quote

Advertisement

You can post new topics in this forum