Inconsistent Behavior in Azure Automation
I need to write a script to grab a file form aws and upload via SFTP. Seemed simple to me.I am doing it in Azure Automation in a Runbook.
I enabled the post-ssh module and made my code. but the execution is inconsistent at best.
I normally get this on the verbose output: Using SSH Username and Password authentication for connection. ssh-ed25519 Fingerprint for sftp.myserver.com: ba:79:3d:78:1f:57:3c:37:20:33:5d:5d:xxxxx Set host key for sftp.myserver.com to ba:79:3d:78:1f:57:3c:37:20:33:5d:5d:xxxxxx
But then I will get "Client Not Connected" or I get "An established connection was aborted by the server" Or, I get a proper connection showing me the session ID but then the next command immediately to post a file I get the above "established connection..." message.
Or, it will simply work! And each time I run it I am in the Runbook Editor test panel and I simply click "start" over and over and I get a different result every time.
It is like it doesn't remember from one moment to the next. I am not changing any code.
The core of the code I'm using is this:
$SFTP = New-SFTPSession -ComputerName $pcURL -Port $pcPort -Credential $ProCareSFTP -ConnectionTimeout 45 -OperationTimeout 45 -KeepAliveInterval 45 -AcceptKey -Verbose
Write-Output $SFTP.SessionID
Set-SFTPItem -SessionID $SFTP.SessionID -Destination "/sandbox" -Path "testing.txt"
I added all the timeouts and keep alive values to see if that would help but it doesn't.
What is going on? does this not work with Azure Automation? It will work 100% of the time with an Azure powershell connection or a personal connection.
Wish I could help but sadly no clue on this one since I do not use Azure or test against Azure. Only step that comes to mind is check on the targeted hosts if the SSHD logs show anything out of the ordinary and if possible do a packet capture to see if a returned error sheds some light.