I've got a batch script which runs via schtasks
every night on different remote Windows PCs (Windows 7 32-bit SP1). These PCs need to FTP files to and from a Linux server. Currently using FTP, the batch script works just fine.
Now the Linux servers are being changed over to use only SFTP. I'd like to write a short PowerShell script to SFTP the same files to/from the server – I've got Posh-Ssh installed to use in PowerShell on these Windows systems (PS Version 5.1).
Currently the part of the batch script doing the FTP looks like this:
REM make temp file for FTP
echo open pos%STORE% > C:\temp\temp.txt
echo username >> C:\temp\temp.txt
echo password >> C:\temp\temp.txt
echo ascii >> C:\temp\temp.txt
echo cd /path/to/use >> C:\temp\temp.txt
echo put %USERDOMAIN%.ftp >> C:\temp\temp.txt
echo put posdaily.txt posdaily.ftp >> C:\temp\temp.txt
echo get prod.txt >> C:\temp\temp.txt
echo get posdaily.ftp >> C:\temp\temp.txt
echo quit >> C:\temp\temp.txt
REM **** FTP to put/get files from POS Server ****
echo First Try Connect to POS ....
ftp -iv -s:\temp\temp.txt >> C:\log\Daily.log 2>&1
Is there a way to use this same temp.txt
that's being created to pass the username/password/put/get to a PowerShell script that uses Posh-Ssh? What changes would I need to make to the temp.txt
file?
I can call a separate batch script which runs the PowerShell script – I've done that in previous batch scripts – but I'm not sure how to write the PowerShell script – what command/commands would I use in the PowerShell script to use the data in temp.txt
?
If I get it working in PowerShell, I should be able to put a call to this same PowerShell script in a C# and VB script that need to do that same thing.