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")
        Else
            MainForm.Server = txtServer.Text
            MainForm.getremotefolders()
            MainForm.Text += "[Logged in]"
            Visible = False
        End If
virgilarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
What .NET version are you working with?  2.0 and higher has the System.Net.FtpWebRequest that is easier to work with.
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.

Thanks

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.