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:
Here's the function I'm writing:
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!
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'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:
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
'===================================================================================================================================
And guess what? Right: I get that "Failure!" message right off the start, with the very 1st file in the laFiles array!
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