[VB6] How to reduce SFTP Connection Rate

Advertisement

mybaek_20170817
Guest

[VB6] How to reduce SFTP Connection Rate

To whom it may concern

I was develop simple Function for Connect SFTP Server and Put File via VB6. Also, I was confirm that my code works fine.
After a few months, I receive E-mail from my clients that said too many SFTP connection were encountered.

Their request is below :
Polling of Directories and File Transfer Rate
- SFTP Users may not poll their directories more than once per minute.
- Maximum number of file transfers per account per hour not to exceed 300.(They told to me that Our Connection per hour is 800.)

My Function is called by Program 4 times per every day. So It is impossible that Our Connection per hour is almost 800. But It is happend.
Unfortunately, I couldn't find the cause of the Problem from My Function.
I would be grateful if you could check my Code and Find the problem if you could.

Here is my CODE below :

Public Function SendSFTP_By_WINSCP(Addr As String, _
                                   Uid As String, _
                                   Attach As String, _
                                   FileName As String, _
                                   HostKey As String, _
                                   sPPK As String, _
                                   Optional Pwd As String = "", _
                                   Optional remotePath As String = "", _
                                   Optional mkdirDirectory As String = "") As Boolean
                                   
On Error GoTo err

    ' Connection Option
    Dim session
    Dim sessionOptions
    
    Set session = New session
    Set sessionOptions = CreateObject("WinSCP.SessionOptions")
    
    Dim myTransferOptions As New TransferOptions
    
    If sPPK <> "" Then
    
         With sessionOptions
            .SshPrivateKeyPath = App.path & "\SSH_PPK\" & sPPK
            
            .PortNumber = 22
            .Protocol = Protocol_Sftp
            .HostName = Addr
            .UserName = Uid
            .SshHostKeyFingerprint = HostKey
        
        End With
        
    ElseIf Pwd <> "" Then
    
         With sessionOptions
            .PortNumber = 22
            .Protocol = Protocol_Sftp
            .HostName = Addr
            .UserName = Uid
            .Password = Pwd
            .SshHostKeyFingerprint = HostKey
        End With
        
    Else
    
        GoTo err
        
    End If
    
    ' Binary Mode로 고정
    myTransferOptions.TransferMode = TransferMode_Binary
        
   ' Connect
    session.DisableVersionCheck = True
    session.Open (sessionOptions)

    If mkdirDirectory <> "" Then
        If (session.FileExists(mkdirDirectory) = False) Then
            session.CreateDirectory (mkdirDirectory)
        End If
    End If
    
    ' UpLoad File
    Dim transferResult As TransferOperationResult
    Set transferResult = session.PutFiles(Attach, remotePath & FileName, False, myTransferOptions)

    ' Throw on Any Error
    If transferResult.check Then
        SendSFTP_By_WINSCP = False
    Else
        SendSFTP_By_WINSCP = True
    End If

    ' Dissconnect, Clean Up
    session.dispose
    Set sessionOptions = Nothing
    Set session = Nothing

Exit Function

err:
' Exception Error
    SendSFTP_By_WINSCP = False
    
    session.dispose
    Set sessionOptions = Nothing
    Set session = Nothing
    
End Function

The dubious part that I think is ' Dissconnect, Clean Up Section. In my opinion, session.Close should be added before session.dispose.
But I confused Because I don't know about difference between session.close and session.dispose.

Sincerely.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: [VB6] How to reduce SFTP Connection Rate

Sorry, but your post does not include enough information.

Anyway, if you call SendSFTP_By_WINSCP four times a day with FileName being a specific file (not a file mask), it will transfer four files a day. And create four connections a day. Except if the connection breaks and WinSCP have to reconnect and resume the transfer. There's nothing we can tell you more without any evidence (log files or anything).

Reply with quote

Advertisement

You can post new topics in this forum