Connection Timed Out after several transfers

Advertisement

scotsun
Joined:
Posts:
2
Location:
United States

Connection Timed Out after several transfers

Good afternoon and thank you for a great program! I have successfully integrated version 5.07 into a vb.Net application that I am using. I am running this on my pc with the webpage on a local server to me and transferring to a remote SFTP server. I normally have no problems whatsoever but recently had to upload about thirty files in succession. My app is programmed to take one file at a time and upload it. I found that after sending 5 files in quick succession, the next send fails with the error:

Error: WinSCP.SessionRemoteException: Network error: Connection timed out. at WinSCP.SessionLogReader.Read(LogReadFlags flags) at WinSCP.ElementLogReader.Read(LogReadFlags flags) at WinSCP.CustomLogReader.TryWaitForNonEmptyElement(String localName, LogReadFlags flags) at WinSCP.CustomLogReader.WaitForNonEmptyElement(String localName, LogReadFlags flags) at WinSCP.CustomLogReader.WaitForNonEmptyElementAndCreateLogReader(String localName, LogReadFlags flags) at WinSCP.CustomLogReader.WaitForGroupAndCreateLogReader() at WinSCP.Session.Open(SessionOptions sessionOptions) at FTNOrders.UploadFileUsingFTP(String FTPFileName, Int32 batch) in Q:\IT\WebSite\MyWeb\Orders.aspx.vb:line 220

I recently added the sftpsession.Dispose() to see if that would correct it but to no avail. I do not see a connection close option but thought that something is not being properly recycled.


This is my code:

Try
' Setup session options
Dim sftpsessionOptions As New SessionOptions
With sftpsessionOptions
.Protocol = Protocol.Sftp
.HostName = "ftpserver.xxxxxxx.com"
.UserName = "MyUserName"
.Password = "MyPassword"
.SshHostKey = "Key here....."
End With

Dim sftpsession As Session = New Session


Using sftpsession
' Connect
sftpsession.Open(sftpsessionOptions)

' Upload files
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Binary

Dim transferResult As TransferOperationResult
transferResult = sftpsession.PutFiles("\\localserver\share\" + Trim(FTPFileName), "/remotedir/", False, transferOptions)

' Throw on any error
transferResult.Check()


' Print results
Dim transfer As TransferEventArgs
For Each transfer In transferResult.Transfers
tbxxx.Text = ("Upload of " + Trim(transfer.FileName) + " succeeded.")
Next
End Using
sftpsession.Dispose()


Catch e As Exception
tbxxx.Text = "Error: " + e.ToString
'Return 1
End Try




Any help with this would be GREATLY appreciated!

Scot Sunnergren

Reply with quote

Advertisement

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

Re: Connection Timed Out after several transfers

It looks like you are creating new connection for every single file. Your FTP server may prevent too many consecutive connections.
Ty to reuse the connection.

Reply with quote

scotsun
Joined:
Posts:
2
Location:
United States

Re: Connection Timed Out after several transfers

Thank you. My problem is that this is subroutine of a web page and not of a console app. It gets called when a button is clicked on the web page to send a file. The session options are created in the sub and the session is opened in the sub. I would have thought that those would then be destroyed when the sub exits normally.

I apologize if this is a stupid question but if I create the session and open the connection when the user first initiates a send, will that session stay open? How do I reconnect to it? On subsequent calls,the session objects will no longer exist. I could store the object in a session variable if that is what it takes... and remove the .Dispose method from the subroutine...

Thank you
Scot

Reply with quote

Advertisement

You can post new topics in this forum