-1

Hi I am trying to upload the file in WinSCP via VBA. the mySession.Open mySessionOptions got Error - Network error connection to "103.231.8.66" time out. i googled but didn't get idea. any suggestion would appreciated

 Sub test()
    Dim wbs As String
     wbs = "D:\Ashok\Work\Loan_Input_Template V8-Library.xlsx"
    Dim mySession As New Session

        ' Enable custom error handling
        On Error Resume Next

       Call Upload(mySession, wbs)

        ' Query for errors
        If Err.Number <> 0 Then
            MsgBox "Error: " & Err.Description

            ' Clear the error
            Err.Clear
        End If

        ' Disconnect, clean up
        mySession.Dispose

        ' Restore default error handling
        On Error GoTo 0

              '  wb.Close SaveChanges:=True

    'FileSystemObject.DeleteFile sPathName

    End Sub

     Private Sub Upload(ByRef mySession As Session, ByRef wb1 As String)  'error line
     Dim wb As Workbook
    Set wb = Workbooks.Open(wb1)
        ' Setup session options
        Dim mySessionOptions As New SessionOptions
        With mySessionOptions
            .Protocol = Protocol_SFTP
            .HostName = "103.231.8.66"
            .UserName = "username"
            .Password = "password"
            .SshHostKeyFingerprint = "ssh-ed25519 256 df:94:44:56:1b:c2:75:8b:b4:58:3a:e2:ef:2e:0d:78"
        End With

        ' Connect

        mySession.Open mySessionOptions ' ERROR LINE

        ' Upload files
        Dim myTransferOptions As New TransferOptions
        myTransferOptions.TransferMode = TransferMode_Binary
        Dim transferResult As TransferOperationResult

'i am not sure this line will working or not

        Set transferResult = mySession.PutFiles(wb, "/home/sftpcf/", False, myTransferOptions)

        ' Throw on any error
        transferResult.Check

        ' Display results
        Dim transfer As TransferEventArgs
        For Each transfer In transferResult.Transfers
            MsgBox "Upload of " & transfer.FileName & " succeeded"
        Next

    End Sub

error msg:

enter image description here

Manual Logging:

enter image description here

JG7
  • 371
  • 2
  • 10
Ashok
  • 284
  • 2
  • 5
  • 23
  • @ashleedawg wb file is opening that is no issue. issue is not opening winscp – Ashok Dec 26 '17 at 12:09
  • Are you able to connect to the IP properly _manually_ from your location? – ashleedawg Dec 26 '17 at 12:12
  • @ashleedawg by manual it is opening but via script it doesn't work – Ashok Dec 26 '17 at 12:13
  • can you share some more information, perhaps including a screenshot of successful login or ping test at [ftp://103.231.8.66/](ftp://103.231.8.66/)? Also, is that the entirety of the code? What's the end goal? – ashleedawg Dec 26 '17 at 12:20
  • @ashleedawg simple logic i want to add the workbook file into Winscp via vba . now i add the images in post – Ashok Dec 26 '17 at 12:30
  • Show us log files for both WinSCP .NET assembly (`Session.SessionLogPath`) and WinSCP GUI. + Are you running both on the **same** machine? – Martin Prikryl Dec 26 '17 at 13:56
  • 2
    Why in the world did you leave credentials in this?!? Please edit your code and remove the login information. Then please change the password to something new. – JG7 Dec 26 '17 at 16:29
  • @JoeyGrant - I saw that too but I assumed (hoped) they aren't the real credentials. Ashok, if that was the real password, you should probably change it on your network (the original posts are still visible online) – ashleedawg Dec 27 '17 at 02:59
  • @MartinPrikryl - Hi Martin, yes i am running on same machine. I have `Session.SessionLogPath` log file , i dont know how to get WinSCP GUI.. is it XML file format? – Ashok Dec 27 '17 at 06:36
  • @MartinPrikryl Please find the .log and .xml file https://drive.google.com/drive/folders/1_vT6K7tQH5Xd8Y6Hx-i268X-TIgyN2-9 – Ashok Dec 27 '17 at 08:04
  • Not, it's not XML file format. Just a regular session log: https://winscp.net/eng/docs/ui_pref_logging - Append the logs to your question. – Martin Prikryl Dec 27 '17 at 09:17
  • @MartinPrikryl have found only one log file in temp folder..i read the what u shared but i dont know how to get it – Ashok Dec 27 '17 at 10:08
  • Sorry, but you are too vague. Did you enable logging in the preferences in GUI? What did you do? + Please accept my answer to your previous question. – Martin Prikryl Dec 27 '17 at 10:13

2 Answers2

0

Finally found answer my question: Adding Port No .PortNumber = XXXX in mySessionOptions and i removed Set wb = Workbooks.Open(wb1). its works perfectly

Ashok
  • 284
  • 2
  • 5
  • 23
0

WinSCP VBA

WinSCP port number defaults to the protocol being used i.e. SFTP port 22, FTP port 21.

The session options defaults for Protocol is SFTP with Port 22.

If you are using SFTP then no port number or protocol is required for sessionOptions.

Below is an example when default SFTP

    Dim mySessionOptions As New SessionOptions
    With mySessionOptions
        .HostName = "103.231.8.66"
        .UserName = "username"
        .Password = "password"
        .SshHostKeyFingerprint = "ssh-ed25519 256 df......"
    End With
SoEzPz
  • 14,958
  • 8
  • 61
  • 64