Topic "[VB6] How to reduce SFTP Connection Rate"

Author Message


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
        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
        SendSFTP_By_WINSCP = True
    End If

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

Exit Function

' Exception Error
    SendSFTP_By_WINSCP = False
    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.

[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27083
Location: Prague, Czechia
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).

You can post new topics in this forum


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