Here is my powershell script that I can use to login to an Cisco Ironport and download all files in the /mail_logs/ folder to my local machine. My problem is if I do not specify a destination file, then the script errors out with "pscp : cannot create file". So If I specify a destination file ($File_MailLogs), then all the files downloaded have the same name, in short all previous files get overwritten. So how do i download all files without getting overwritten.
$SOFTWARE_PATH = "E:\Software\putty_32bit"
$SCRIPTS_PATH = "E:\Scripts_Do_Not_Delete"
$PRIVKEY = $SCRIPTS_PATH + "\IronportClusEval.ppk"
$Folder_MailLogs = "c:\temp\IronPort_MailLogs\"
$File_MailLogs = $Folder_MailLogs + "test.txt"
if ( -not (Test-Path $Folder_MailLogs -PathType Container) ) { mkdir $Folder_MailLogs }
$RemoveFiles_String = $Folder_MailLogs + "\*.txt"
Remove-Item $RemoveFiles_String
$IronPortServer = ("aaa-bbb-101.com")
$source_file = "admin@" + $IronPortServer + ":/mail_logs/*"
echo y | &($SOFTWARE_PATH + "/pscp.exe") -i $PRIVKEY $source_file $File_MailLogs
See screenshot of the running script, showing that all the files are actually being downloaded
I had to use the UNSAFE option as described in https://www.ssh.com/ssh/putty/putty-manuals/0.68/Chapter5.html. With this I was able to download all files (without being overwritten). So the command is:
echo y | &($SOFTWARE_PATH + "/pscp.exe") -unsafe -i $PRIVKEY $source_file $Folder_MailLogs