Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File transfer with WinCSP fails 1

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
571
US
Colleagues,
I'm still struggling with this lil' thingy in the subject line. My problem is that I still cannot find comprehensive description for the functions/methods of this WinCSPnet utility program...
To prevent obvious question: I have it put in the Reference section of the Project:

20200902_WinCSPnet_DoNotTransferFiles_rm8lbn.jpg


Here's the function I'm writing:

Code:
'===================================================================================================================================
Public Function WinSFTP_Send(ByVal tcHostName As String, ByVal tcUserName As String, ByVal tcPW As String, _
                             ByVal SSHKFP As String, ByVal tcSrcDir As String, ByVal tcSrcFileName As String, _
                             ByVal tcDstDir As String) As Boolean
'===================================================================================================================================
Dim llRet As Boolean = True, lcLogStr As String = "", lcErrStr As String = "", loSessionOptions As New SessionOptions, _
    lcDstDir As String = AddBackSlash(tcDstDir)
Dim liWildCardChrCnt As Int16 = GetChrCount("*", tcSrcFileName), lcFullPath2File As String, lcJustFName As String
Dim laFiles(0) As String

If liWildCardChrCnt > 0 Then
   laFiles = Directory.GetFiles(tcSrcDir)
Else
   laFiles(0) = AddBackSlash(tcSrcDir) & tcSrcFileName
End If

' Array laFiles[] contains now full path to each of the source files in the source directory

With loSessionOptions
   .Protocol = Protocol.Sftp
   .HostName = tcHostName
   .UserName = tcUserName
   .Password = tcPW
'   .SshHostKeyFingerprint = SSHKFP
   .GiveUpSecurityAndAcceptAnySshHostKey = True
End With

Using loSession As New Session
   Dim loTransferResult As TransferOperationResult, loTransferOptions As New TransferOptions
' Connect
   loSession.Open(loSessionOptions)

' Upload files
   loTransferOptions.TransferMode = TransferMode.Binary

   Try

      For Each lcFullPath2File In laFiles
         lcJustFName = Path.GetFileName(lcFullPath2File)

         loTransferResult = loSession.PutFiles(lcFullPath2File, lcDstDir & lcJustFName, False, loTransferOptions)

         If Not File.Exists(lcDstDir & lcJustFName) Then
            llRet = False
            lcLogStr = lcLogStr & Now.ToString("yyyy-MM-dd HH:mm:ss") & ": transfer of the file" & lcFullPath2File & _
                 vbCrLf & Space(21) & "to " & tcDstDir & " failed!" & vbCrLf & Space(21) & "Program quits." & vbCrLf
            Write2Log(gcLogFile, lcLogStr, True)

            If glDevelop Then
               MsgBox("Transfer of the file " & lcFullPath2File & " to " & tcDstDir & " failed!" & vbCrLf & "Program quits.", _
                     MsgBoxStyle.Critical, "File transfer failed!")
            End If

            Exit For
         End If

      Next

   Catch loErr As Exception
      lcLogStr = lcLogStr & Now.ToString("yyyy-MM-dd HH:mm:ss") & ": ERROR OCCURED while transfering file" & lcFullPath2File & _
                 vbCrLf & Space(21) & "to " & tcDstDir & "!" & vbCrLf & Space(21) & loErr.Message & _
                 vbCrLf & Space(21) & "Occured in " & vbCrLf & Space(21) & loErr.Source & vbCrLf & Space(21) & _
                 loErr.StackTrace & vbCrLf & Space(21) & "Program quits." & vbCrLf
      llRet = False
      Write2Log(gcLogFile, lcLogStr, True)

      If glDevelop Then
         lcErrStr = "ERROR OCCURED!" & vbCrLf & loErr.Message & vbCrLf & "Occured in " & vbCrLf & loErr.Source & vbCrLf & _
                     loErr.StackTrace & vbCrLf & "Program quits."
         MsgBox(lcErrStr, MsgBoxStyle.Critical, gcAppName & ": WinCSP failed!")
      End If

   End Try

   loSession.Close()
   loSession.Dispose()
End Using

Return llRet
End Function
'===================================================================================================================================
Note: tcHostName is given as a string with IP address, the rest - just as strings.
And guess what? Right: I get that "Failure!" message right off the start, with the very 1st file in the laFiles array! [hairpull]
You see, I do not even know if the loSession.Open(loSessionOptions) works, let alone whether it's a procedure or a function (and if it's the latter - what data type it returns...)

Could those of you who works with that WinCSPnet.DLL enlighten this ignorant one, proshe bardzo panove, por favor, please?

TIA!

Since, as I've said before, I have no


Regards,

Ilya
 
I sent you a link to the WinSCP documentation in your thread1867-1804756

Granted, that was to the root of the documentation but, albeit not immediately obvious, just a few clicks on that site leads to WinSCP .NET Assembly and COM Library
 
Thank you!
Unfortunately, it turns out that session.Open() is a function only by name (by C/C++ terms): public void Open() doesn't return any value.
(The term "Method" seems ambiguous to yours truly coz it can be a procedure as well as a function. In the case in question - it's a procedure.)
Bottom line: we do not know if the "line is open" or not... [sigh]
Well, as ancients said, "negative result is still a result" (albeit, as one of my bosses once said, "it won't brings profit"...)

BTW, it seems we have some older version of WinSCPnet.DLL here: when I tried to use Session.PutFilesToDirectory() (instead of one-by-one with PutFiles() in FOR EACH - NEXT cycle) - VS 2012 "informed" me that Session object has no PutFilesToDirectory method... :-(

Regards,

Ilya
 
>we do not know if the "line is open" or not.

There is a property of the Session class that can tell you this: Session.Opened
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top