Network Stream Object Reference not set to an instance of an objet

I am trying to create an FTP application using TCPClient. The code below attempts to log on to a FTP server. I have set up my machine to work as a server and i am using the code below to gain access to the files and folders. However, i keep getting an error message on the "MainForm.NetStrm = clientSocket.GetStream()" line saying that Object Reference has not been set to an instance of an object.
I declared the NetStrm variable as Networkstream but i cannot declare NetStrm as new NetworkStream.

Any ideas of what i am doing wrong? Thanks

 Dim clientSocket As New TcpClient

        clientSocket.Connect(txtServer.Text, 21)

        MainForm.NetStrm = clientSocket.GetStream()

        Dim RdStrm As StreamReader = New StreamReader(MainForm.NetStrm)

        txtStatus.Text = RdStrm.ReadLine

        txtStatus.Text = MainForm.sendFTPcmd("User " + txtUserName.Text + vbCrLf)

        txtStatus.Text = MainForm.sendFTPcmd("Pass " + txtPassword.Text + vbCrLf)

        If txtStatus.Text.Substring(0, 3) <> "230" Then
            MessageBox.Show("Failed to log in")
            MainForm.Server = txtServer.Text
            MainForm.Text += "[Logged in]"
            Visible = False
        End If
Who is Participating?
virgilarAuthor Commented:
I have figured out what the problem was. Sorry for wasting everybody's time but the problem was with a couple lines of code not extantiating the networkstream object properly.

Bob LearnedCommented:
What .NET version are you working with?  2.0 and higher has the System.Net.FtpWebRequest that is easier to work with.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.