SFTP script error

Advertisement

Identis
Joined:
Posts:
4
Location:
Lithuania

SFTP script error

Hello,
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?

Reply with quote

Advertisement

Identis
Joined:
Posts:
4
Location:
Lithuania

Different errors:
* 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.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: SFTP script error

Can you connect to that SFTP server anyhow from that specific local machine? Using WinSCP GUI? Using any other SFTP client?

Reply with quote

Identis

Re: SFTP script error

Yes I can connect with WinSCP GUI without problem. And if I run script with PowerShell manually it's working. But with Task Scheduler it's failing randomly (it can fail every second run or 2-3 times from 5).

Reply with quote

Advertisement

Guest

Troubleshooting SFTP Connections
Verify that the server you are connecting to supports SFTP connections (see Note below).
Verify the connection port.
Try toggling the compression options in the SSH2 Security page.
Verify the authentication mechanism supported and required by the server.

This may help you,
Rachel Gomez

Reply with quote

Advertisement

sftp_cody
Joined:
Posts:
1

Time Out waiting for server to respond

Hello,
I'm running into this issue as well. Can login to the sftp site from the web, winscp etc. This is only failing as a scheduled task. It's quite hit or miss. Sometimes it connects, other times i get the "time out waiting for server to respond"[i] error. I've tried this using command prompt, tried it with .NET via PowerShell. Still having the same issue.
When I run the batch file manually, it works. Just not the scheduled task. Been battling this for months now. Any help is highly appreciated
command:
open username:password@sftpserver -hostkey=""
PowerShell:
# 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()
}
Service account being used is a local admin also and added to Log on as a batch local security policy

Reply with quote

martin
Site Admin
martin avatar

Re: Time Out waiting for server to respond

@sftp_cody: It's hardly anything within WinSCP that is causing the instability. So no parameter can change it. You may need to add some retry mechanism to your code.

Reply with quote

Advertisement

You can post new topics in this forum