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

Posted on 2008-11-15
Medium Priority
Last Modified: 2013-11-13
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
Question by:virgilar
LVL 96

Expert Comment

by:Bob Learned
ID: 22970600
What .NET version are you working with?  2.0 and higher has the System.Net.FtpWebRequest that is easier to work with.

Accepted Solution

virgilar earned 0 total points
ID: 22987836
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.


Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question