Topic "session.executecommand adjusting timeout"

Author Message
paul.jobb
[View user's profile]

Joined: 2014-07-02
Posts: 1
Hi;

I have a powershell script that's using the .net assembly, I am using the executecommand to run a shell script that is rather long running and it appears to terminate the process after about a minute with the following message

Exception calling "ExecuteCommand" with "1" argument(s): "Terminated by user."- error creating ssh session

Is there anyway to increase the timeout value on the execute statement?

The code works against another server where the process I am calling runs under a minute with no issue. Attached is the portion of the script using winscp, its failing at $session.executecommand("./reconfigure_nagios.sh").output

try {
# Load WinSCP .NET assembly
# Use "winscp.dll" for the releases before the latest beta version.
[Reflection.Assembly]::LoadFrom("c:\program files\winscp\WinSCP.dll") | Out-Null
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = $sshhost
$sessionOptions.UserName = $sshid
$sessionOptions.Password = $sshpw
$sessionOptions.SshHostKeyFingerprint = $hostkeyfingerprint.Get_Item($sshhost)

$session = New-Object WinSCP.Session
try {
# Connect
$session.Open($sessionOptions)
# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult = $session.PutFiles("$cfgfolder\*", "/usr/local/nagios/etc/import/", $False, $transferOptions)
# Throw on any error
$transferResult.Check()
# Print results
foreach ($transfer in $transferResult.Transfers)
{
"Upload of " + $transfer.FileName + " succeeded"
Remove-Item $transfer.FileName
}
remove-item $cfgfolder
"Removing configuration folder" + $cfgfolder
if ($applyconfig) {
$copytodirectory = $session.ListDirectory("/usr/local/nagios/etc/import/")
if ($copytodirectory.files.count -gt 2) {
"Applying Configuration on " + $sshhost
$session.executecommand(" cd /usr/local/nagiosxi/scripts")
$session.executecommand("./reconfigure_nagios.sh").output
}
else {"usr/local/nagios/etc/import/ directory on " + $sshhost + " empty, configuration not applied."}
}
}
finally {
# Disconnect, clean up
$session.Dispose()
}
}
catch {
$_.Exception.Message + "- error copying files. config files created in " + $cfgfolder + ",please manually upload to nagios"
}
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25025
Location: Prague, Czechia
Use SessionOptions.Timeout:
https://winscp.net/eng/docs/library_sessionoptions
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License