Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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"
sleepersimulant

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)
martin

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

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'.
martin

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"
sleepersimulant

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