Topic "session.executecommand adjusting timeout"

Author Message
[View user's profile]

Joined: 2014-07-02
Posts: 1

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("./").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
# 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
# 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")
else {"usr/local/nagios/etc/import/ directory on " + $sshhost + " empty, configuration not applied."}
finally {
# Disconnect, clean up
catch {
$_.Exception.Message + "- error copying files. config files created in " + $cfgfolder + ",please manually upload to nagios"
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24736
Location: Prague, Czechia
Use SessionOptions.Timeout:
Martin Prikryl

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!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License