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

Posted on 2008-11-15
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
    What .NET version are you working with?  2.0 and higher has the System.Net.FtpWebRequest that is easier to work with.

    Accepted Solution

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now