Program freezes after a timeout
Greetings,
I'm developing a SFTP client, I'm connecting and downloading and everything. the problem comes with I'm downloading a big file >10Gb. I get a "A first chance exception of type 'System.TimeoutException' occurred in WinSCPnet.dll" the program keeps downloading with the filepart files. it downloads the complete folder from the server, the problem is that I have some other method or functions after the download and it's not getting there.
So, I don't Understand why after a time out it resumes but it doesn't run all the code.
can somebody explain me what is happening here?
Part of my code
Try
' Set up session options
Select Case opt
Case 1 ' Connect
AddHandler session.FileTransferProgress, AddressOf SessionFileTransferProgress
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
.HostName = "xxx"
.PortNumber = xxx
.UserName = "xxx"
.SshHostKeyFingerprint = "xxx"
.SshPrivateKeyPath = "xxxx"
.Timeout = New TimeSpan(26000)
.AddRawSettings("FSProtocol", "x")
.AddRawSettings("ProxyMethod", "x")
.AddRawSettings("ProxyHost", "xxxx")
.AddRawSettings("ProxyPort", "x")
End With
session.Open(sessionOptions)
MsgBox("Connection succesful", MsgBoxStyle.OkOnly)
flag = True
Case 6 ' download
Form1.ProgressBar1.Visible = True
Form1.lbldown.Visible = True
Form1.Label4.Visible = True
' Download files
'
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Binary
transferOptions.ResumeSupport.State = TransferResumeSupportState.On
transferOptions.OverwriteMode = OverwriteMode.Resume
Path = Form1.txtfolder.Text.ToString
If Path = "" Then
MsgBox("Please select a valid path", MsgBoxStyle.Critical)
Else
Dim transferResult As TransferOperationResult
namefile = downloadpath.Remove(0, 1)
Path += "\" & namefile
Form1.ProgressBar1.Visible = True
transferResult= session.GetFiles(downloadpath, Path, False, transferOptions)
GoTo check
' Throw on any error
transferResult.Check()
If transferResult.IsSuccess = True Then
Goto check
Else
MsgBox("Download incompleted", MsgBoxStyle.Exclamation)
End If
End If
Private Shared Sub SessionFileTransferProgress(
sender As Object, e As FileTransferProgressEventArgs)
' New line for every new file
If (_lastFileName IsNot Nothing) AndAlso (_lastFileName <> e.FileName) Then
Form1.Label4.Visible = True
Form1.ProgressBar1.Invoke(New Action(Of Double)(AddressOf UpdateProgress), e.OverallProgress)
Form1.ProgressBar1.Visible = True
' Form1.lbldown.Text = e.FileName
Dim a = e.FileName.Substring(e.FileName.LastIndexOf("/"))
Form1.lbldown.Text = a
End If
'Remember a name of the last file reported
_lastFileName = e.FileName
local = e.Directory
End Sub
Private Shared _lastFileName As String
Private Shared Sub UpdateProgress(progress As Double)
Form1.ProgressBar1.Value = progress * 100
End Sub
I'm developing a SFTP client, I'm connecting and downloading and everything. the problem comes with I'm downloading a big file >10Gb. I get a "A first chance exception of type 'System.TimeoutException' occurred in WinSCPnet.dll" the program keeps downloading with the filepart files. it downloads the complete folder from the server, the problem is that I have some other method or functions after the download and it's not getting there.
So, I don't Understand why after a time out it resumes but it doesn't run all the code.
can somebody explain me what is happening here?
Part of my code
Try
' Set up session options
Select Case opt
Case 1 ' Connect
AddHandler session.FileTransferProgress, AddressOf SessionFileTransferProgress
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
.HostName = "xxx"
.PortNumber = xxx
.UserName = "xxx"
.SshHostKeyFingerprint = "xxx"
.SshPrivateKeyPath = "xxxx"
.Timeout = New TimeSpan(26000)
.AddRawSettings("FSProtocol", "x")
.AddRawSettings("ProxyMethod", "x")
.AddRawSettings("ProxyHost", "xxxx")
.AddRawSettings("ProxyPort", "x")
End With
session.Open(sessionOptions)
MsgBox("Connection succesful", MsgBoxStyle.OkOnly)
flag = True
Case 6 ' download
Form1.ProgressBar1.Visible = True
Form1.lbldown.Visible = True
Form1.Label4.Visible = True
' Download files
'
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Binary
transferOptions.ResumeSupport.State = TransferResumeSupportState.On
transferOptions.OverwriteMode = OverwriteMode.Resume
Path = Form1.txtfolder.Text.ToString
If Path = "" Then
MsgBox("Please select a valid path", MsgBoxStyle.Critical)
Else
Dim transferResult As TransferOperationResult
namefile = downloadpath.Remove(0, 1)
Path += "\" & namefile
Form1.ProgressBar1.Visible = True
transferResult= session.GetFiles(downloadpath, Path, False, transferOptions)
GoTo check
' Throw on any error
transferResult.Check()
If transferResult.IsSuccess = True Then
Goto check
Else
MsgBox("Download incompleted", MsgBoxStyle.Exclamation)
End If
End If
Private Shared Sub SessionFileTransferProgress(
sender As Object, e As FileTransferProgressEventArgs)
' New line for every new file
If (_lastFileName IsNot Nothing) AndAlso (_lastFileName <> e.FileName) Then
Form1.Label4.Visible = True
Form1.ProgressBar1.Invoke(New Action(Of Double)(AddressOf UpdateProgress), e.OverallProgress)
Form1.ProgressBar1.Visible = True
' Form1.lbldown.Text = e.FileName
Dim a = e.FileName.Substring(e.FileName.LastIndexOf("/"))
Form1.lbldown.Text = a
End If
'Remember a name of the last file reported
_lastFileName = e.FileName
local = e.Directory
End Sub
Private Shared _lastFileName As String
Private Shared Sub UpdateProgress(progress As Double)
Form1.ProgressBar1.Value = progress * 100
End Sub