Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

File transfer with WinCSP fails

File transfer with WinCSP fails

File transfer with WinCSP fails

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:

Here's the function I'm writing:


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)
   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

' Upload files
   loTransferOptions.TransferMode = TransferMode.Binary


      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


   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

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?


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



RE: File transfer with WinCSP fails

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... sad



RE: File transfer with WinCSP fails

>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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close