0 Replies - 1186 Views - Last Post: 02 October 2012 - 02:28 AM Rate Topic: -----

#1 Bless841  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-January 11

vb.net gain access to remote server(IP addr) and Check if file exists

Posted 02 October 2012 - 02:28 AM

Good day,

I have transfered file from FTP Server to a Client's Remote Server.

See code:
Public Sub SendSMSFile ()   
        Dim sl As UniSelectList = Nothing
        Dim UV_FILE As IBMU2.UODOTNET.UniFile
        Dim UV_SESSION As UniSession = Nothing
        Dim myStreamWriter As StreamWriter = Nothing
        Dim lngWnd As Long = Nothing
        Dim strTxtfile As String = Nothing

        Try
            UV_SESSION = UniObjects.OpenSession("ccqs", "root", "secten", "/disk1/ccqs", "uvcs")
            If UV_SESSION.IsActive Then
                sl = UV_SESSION.CreateUniSelectList(2)
                UV_FILE = UV_SESSION.CreateUniFile("SEC.SMSES")

                If UV_FILE.IsFileOpen Then
                    Try
                        sl.Select(UV_FILE)
                        ' Dim dbWebItems As Object = onetFile
                        Dim lLastRecord As Boolean = sl.LastRecordRead

                        Do
                            Dim strSMSfile As String = sl.Next()
                            If strSMSfile <> "" Then
                                If strSMSfile.StartsWith("SMS_") Then
                                    Dim strIndex As String = strSMSfile.IndexOf("_")

                                    Dim StrYear As String = strSMSfile.Substring(strIndex + 1, 4)
                                    Dim strMM As String = strSMSfile.Substring(8, 2)

                                    Dim strDay As String = strSMSfile.Substring(10, 2)

                                    Dim dteToday As Date = Date.Today

                                    Dim DateFormat As String = "dd MMMM yyyy"
                                    Dim dtedate As Date = StrYear & "-" & strMM & "-" & strDay

                                    dtedate = dtedate.ToString(DateFormat)
                                    dteToday = dteToday.ToString(DateFormat)

                                    If dtedate = dteToday Then
                                        myStreamWriter = File.CreateText("F:\SMS_FILE\sms.txt")
                                        With myStreamWriter
                                            .WriteLine("open ccqs")
                                            .WriteLine("root")
                                            .WriteLine("secten")
                                            .WriteLine("lcd F:\SMS_FILE")
                                            .WriteLine("cd /disk1/ccqs/SEC.SMSES")
                                            .WriteLine("bin")
                                            .WriteLine("get" & " " & strSMSfile)
                                            .WriteLine("disconnect")

                                            .WriteLine("open 196.26.15.156")
                                            .WriteLine("sectftp")
                                            .WriteLine("sectptf")
                                            .WriteLine("cd SMS_batch_outbound/new")
                                            .WriteLine("bin")
                                            .WriteLine("put" & " " & strSMSfile)
                                            .WriteLine("disconnect")
                                            .WriteLine("bye")
                                            .WriteLine("close")
                                            .Flush()
                                            myStreamWriter.Close()
                                        End With
                                        strTxtfile = "F:\SMS_FILE\sms.txt"
                                        lngWnd = Shell("ftp -s:" & strTxtfile, vbMinimizedFocus)
                                        Sleep(5000)

                                            Catch UniversEx As Exception
                                                Dim objEmail As New clsEmail

                                                clsEmail.SendMailMessage("gaithn@gtsc.co.za ", _
                                                            " seanm@gtsc.co.za ", "cynthian@gtsc.co.za, "", _
                                                            "Automation Error " & Space(10) & "@" & "UpdateSMSMonitoring", UniversEx.Message.ToString() & _
                                                            vbNewLine & UniversEx.Source.ToString())
                                                objEmail = Nothing
                                            Finally
                                                UV_SESSION = Nothing
                                                dbFTPDetails = Nothing
                                            End Try
                                        End If
                                    End If
                                End If

                            End If
                        Loop Until sl.LastRecordRead
                    Catch ex As Exception
                    End Try
                End If
            End If
        Catch ex As Exception
        Finally
            UV_SESSION = Nothing
            dBaseControl = Nothing
        End Try
    End Sub



After I've transfered a file. I want to be able to Open the Server to check if the file is there and that's where my problem is. I've tried this code but it is not working. See below code:

                                        If lngWnd Then
                                            Try

                                                Dim oConn As ConnectionOptions = New ConnectionOptions
                                                oConn.Username = "sectftp"
                                                oConn.Password = "sectptf"
                                                Dim strNameSpace As String = "//196.26.15.156/"

                                                strNameSpace = strNameSpace & "SMS_batch_outbound/new"
                                                Dim oMs As ManagementScope = New ManagementScope(strNameSpace, oConn)
                                                If strNameSpace <> "" Then

                                                    UV_SESSION = UniObjects.OpenSession("ccqs", "root", "secten", "/disk1/ccqs", "uvcs")
                                                    Cmd = UV_SESSION.CreateUniCommand()
                                                    Cmd.Command = "SMS.MONFILE"
                                                    Cmd.Execute()
                                                Else
                                                    MsgBox("file doesnt exist")
                                                End If




Please assist

Is This A Good Question/Topic? 0
  • +

Page 1 of 1