SFTP script error
maybe you can help me. I get random time error about connection to SFTP. I'm running script with Task scheduler. If I run script manually I didn't receive error. Where is the problem?
Advertisement
Advertisement
* 2022-10-31 10:56:32.730 **Timeout waiting for server to respond.** . 2022-10-31 10:56:32.730 Closing connection. < 2022-10-31 10:56:32.730 Script: Timeout waiting for server to respond. ------------------------------------------------------------------------- < 2022-10-31 11:10:19.280 Script: Host is not communicating for more than 15 seconds. < 2022-10-31 11:10:19.280 Still waiting... < 2022-10-31 11:10:19.280 Note: If the problem repeats, try turning off 'Optimize connection buffer size'. < 2022-10-31 11:10:19.280 Warning: Aborting this operation will close connection! . 2022-10-31 11:10:22.421 Data has arrived, closing query to user. . 2022-10-31 11:10:22.421 Answer: OK . 2022-10-31 11:10:22.421 Network error: Software caused connection abort < 2022-10-31 11:10:22.421 Script: Network error: Software caused connection abort < 2022-10-31 11:10:22.421 Cannot initialize SFTP protocol. Is the host running an SFTP server? ------------------------------------------------------------------------------- . 2022-10-31 11:50:18.898 Wait for another 15 seconds?** () < 2022-10-31 11:50:18.898 Script: Host is not communicating for more than 15 seconds. < 2022-10-31 11:50:18.898 Still waiting... < 2022-10-31 11:50:18.898 Note: If the problem repeats, try turning off 'Optimize connection buffer size'. < 2022-10-31 11:50:18.898 Warning: Aborting this operation will close connection! . 2022-10-31 11:51:33.319 Answer: No . 2022-10-31 11:51:33.319 Attempt to close connection due to fatal exception: * 2022-10-31 11:51:33.319 **Timeout waiting for server to respond.** . 2022-10-31 11:51:33.319 Closing connection. < 2022-10-31 11:51:33.319 Script: Timeout waiting for server to respond. < 2022-10-31 11:51:33.319 Authentication log (see session log for details): < 2022-10-31 11:51:33.319 Using username "paukstynas.sftp". < 2022-10-31 11:51:33.319 < 2022-10-31 11:51:33.319 Authentication failed.
Advertisement
Advertisement
open username:password@sftpserver -hostkey=""
# Load WinSCP .NET assembly Add-Type -Path 'C:\Program Files (x86)\WinSCP\WinSCPnet.dll' # Set up session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "" UserName = "" Password = "" SshHostKeyFingerprint = "" TimeoutInMilliseconds = 60000 } $sessionOptions.AddRawSettings("SendBuf", "0") $sessionOptions.AddRawSettings("SshSimple", "0") $session = New-Object WinSCP.Session try { $session.SessionLogPath = "C:\BatchFiles\Logs\EJLog_$dateString.log" # Connect $session.Open($sessionOptions) # Upload files $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary $transferOptions.FilePermissions = $Null # This is default $transferOptions.PreserveTimestamp = $False $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off $transferOptions.AddRawSettings("BufferSize", "000000") # Set buffer size to 100 KB $transferOptions.AddRawSettings("Timeout", "120000") # Set timeout to 60 seconds $transferOptions.AddRawSettings("ErrorHandling", "2") # Ignore permission errors $transferResult = $session.PutFiles("$journal", "$remotedestination", $False, $transferOptions) # Throw on any error $transferResult.Check() foreach ($transfer in $transferResult.Transfers) { Write-Host "Upload of $($transfer.FileName) succeeded" } # Your code } finally { $session.Dispose() }
Advertisement
You can post new topics in this forum