Hello, connect/ get
Hello guys, I have this powershell code.
Works good but when add more line in db.csv doesn't work with return error code:
When I have per example only 2 line in db.csv the script works very well
I try with 19 hostname and Ip addr line in CSV doc and works, but when I add only 1 more stopping works.
19 works
20+ doesn't work..
Any idea? (Thank you and sorry for my english)
Works good but when add more line in db.csv doesn't work with return error code:
Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed. Server sent command exit status 0.
Authentication log (see session log for details):
Using username "username".
Authentication failed."
At C:\Users\me\Desktop\testeScript\CollectLog.ps1:41 char:5
+ $session.Open($sessionOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SessionRemoteException
When I have per example only 2 line in db.csv the script works very well
HostName,IP name1,10.10.1.1 name2,10.10.1.2
19 works
20+ doesn't work..
Any idea? (Thank you and sorry for my english)
Add-Type -Path "WinSCPnet.dll" $Name = @() $ip = @() Import-Csv db.csv |` ForEach-Object { $Name += $_.HostName $ip += $_.IP } $inputID = Read-Host -Prompt "Type ID" if ($Name -contains $inputNumber) { $Where = [array]::IndexOf($Name, $inputID) Write-Host "IP: " $ip[$Where] } # Set up session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "$ip" UserName = "username" Password = "password" GiveUpSecurityAndAcceptAnySshHostKey = "true" } $session = New-Object WinSCP.Session try { # Connect $session.Open($sessionOptions) # Transfer files $session.GetFiles("/C:/Program Files/Common Files/logs/Device.log", "E:\loguri\Log\Arhive\*").Check() } finally { $session.Dispose() } Compress-Archive -Path "E:\loguri\Log\Arhive\Device.log" -DestinationPath "E:\loguri\Log\Arhive\$inputID.zip" -Update Remove-Item -Path "E:\loguri\Log\Arhive\Device.log" -Force