VB.NET - Issues with VB.NET FTP Class to UNIX FTP Server

All, 
This is probably a much harder question than what should go in the "Getting Started" forum, but I am new and don't know where to put it. Anyways, I am currently developing an FTP class in VB.NET. It's kid tested, mother approved when trying to access an FTP Server on a Windows box meaning I can connect, run commands, upload and download a file no problem. My issues come when I try to use the same class with the same commands to access an FTP server on a UNIX box. I can connect and login just fine, but after that all my commands come back "500 'PWD': command
not understood.". This is for commands as simple as "PWD" or "CWD" Has anyone experienced this error and can help me solve it. In order to help everyone out the following is my class. You should be able to just cut and paste it into VS 2003:

Imports System
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Text.ASCIIEncoding
Imports System.Net.Sockets
Imports System.Configuration
Imports System.Resources

Public Class FTPClient

#Region "Local Properties"

    '''<summary>
    ''' Public Property: Host - String variable.
    '''</summary>
    Public Property Host() As String
        Get
            Return _Host
        End Get
        Set(ByVal Value As String)
            _Host = Value
        End Set
    End Property

    '''<summary>
    ''' Public Property: Path - String variable.
    '''</summary>
    Public Property Path() As String
        Get
            Return _Path
        End Get
        Set(ByVal Value As String)
            _Path = Value
        End Set
    End Property

    '''<summary>
    ''' Public Property: User - String variable.
    '''</summary>
    Public Property User() As String
        Get
            Return _User
        End Get
        Set(ByVal Value As String)
            _User = Value
        End Set
    End Property

    '''<summary>
    ''' Public Property: Password - String variable.
    '''</summary>
    Public Property Password() As String
        Get
            Return _Password
        End Get
        Set(ByVal Value As String)
            _Password = Value
        End Set
    End Property

    '''<summary>
    ''' Public Property: Password - String variable.
    '''</summary>
    Public Property Port() As String
        Get
            Return _Port
        End Get
        Set(ByVal Value As String)
            _Port = Value
        End Set
    End Property

    '''<summary>
    ''' Public ReadOnly Property: ResponseCode - String variable.
    '''</summary>
    Public ReadOnly Property ResponseCode() As String
        Get
            Return _ResponseCode
        End Get
    End Property

    '''<summary>
    ''' Public ReadOnly Property: ResponseData - String variable.
    '''</summary>
    Public ReadOnly Property ResponseData() As String
        Get
            Return _ResponseData
        End Get
    End Property

#End Region

    ' FTP Default Properties.
    Private _Host As String = "127.0.0.1"
    Private _Path As String = "."
    Private _User As String = "anonymous"
    Private _Password As String = "anonymous@nowhere.com"
    Private _Port As Integer = 21
    Private _ResponseCode As Integer
    Private _ResponseData As String
    Private _FTPCommandSocket As Socket = Nothing
    Private _FTPLogin As Boolean = False
    Private _FTPCommandSocketInstalled As Boolean = False

#Region "Public Methods"

    Public Sub New()

    End Sub

    '''<summary>
    ''' Public Function: Login - This function will create a command and data socket and then send the
    ''' login credentials to the FTP host. 
    '''</summary>
    '''<returns>Function returns a Boolean.</returns>
    Public Function Login() As Boolean

        ' Create an FTP command socket.
        CreateCommandSocket()

        ' Send the gathered login information to the FTP host.
        Try
            SendCommand("USER", _User)
            SendCommand("PASS", _Password)
            _FTPLogin = True
        Catch ex As Exception
            ' Login did not work because the FTP login information was not accepted.
            _ResponseData = "FTP Login function not executed."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP login information was not accepted", ex)
            Return False
        End Try

        ' Login successful.
        Return True

    End Function

    '''<summary>
    ''' Public Sub: Logout - This subroutine will disconnect and close an FTP command and data socket.
    '''</summary>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub Logout()

        ' Close and destroy the FTP command socket.
        If (_FTPCommandSocket Is Nothing = False) Then
            SendCommand("QUIT", "")
            _FTPCommandSocket.Close()
            _FTPCommandSocket = Nothing
        End If
    End Sub

    '''<summary>
    ''' Public Sub: SendCommand - Provided a Command and Arguements, this subroutine will execute an FTP Command.
    ''' Commands already taken care of with subroutines below:
    ''' TYPE:   Mode (ASCII or Binary)
    ''' NLST:   List files in directory
    ''' SIZE:   Get file Size
    ''' RETR:   Download a file
    ''' STOR:   Upload a file
    ''' DELE:   Delete a file
    ''' RNFR:   Select a file to be renamed
    ''' RNTO:   Rename a selected file
    ''' PWD:    Get a current directory
    ''' CWD:    Change directory
    ''' RDM:    Remove a directory
    '''</summary>
    '''<param name="FTPCommand">As String</param>
    '''<param name="FTPCommandArguements">As String</param>
    '''<returns>Function returns an FTP stream.</returns>
    Public Sub SendCommand(ByVal FTPCommand As String, ByVal FTPCommandArguments As String)

        ' Combine FTP command with the FTP command arguements.
        Dim _FTPCommand As String = FTPCommand & " " & FTPCommandArguments
        _FTPCommand += Environment.NewLine

        ' Convert the FTP command into ASCII text.
        Dim commandBytes() As Byte = ASCII.GetBytes(_FTPCommand)

        Try
            ' Execute the FTP command on the FTP host.
            _FTPCommandSocket.Send(commandBytes, commandBytes.Length, 0)
            ReadResponse()
        Catch ex As Exception
            ' Command was not executed.
            _ResponseData = "FTP SendCommand subroutine not executed."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP command was not accepted", ex)
        End Try
    End Sub

    '''<summary>
    ''' Public Sub: SetBinaryMode - This subroutine sets the FTP mode to binary.
    '''<param name="mode">As Boolean</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub SetBinaryMode(ByVal mode As Boolean)

        If (mode) Then
            'Send the FTP TYPE command as binary.
            SendCommand("TYPE ", "I")
        Else
            'Send the FTP TYPE command as ASCII.
            SendCommand("TYPE ", "A")
        End If
    End Sub

    '''<summary>
    ''' Public Function: GetDirectoryFileList - This function will get the names of the files from the provided directory name.
    '''</summary>
    '''<param name="directoryName">As String</param>
    '''<returns>Function returns a string.</returns>
    Public Function GetFileList(ByVal directoryName As String) As String()

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        ' Create an FTP data socket.
        Dim _FTPDataSocket As Socket = CreateDataSocket()

        'Send an FTP NLST command.
        SendCommand("NLST ", directoryName)

        Const _EndLine As Char = "\n"
        Const _BufferSize As Integer = 512

        Dim _Data As String = ""
        Dim _Buffer(_BufferSize) As Byte
        Dim _BytesRead As Integer = 0

        If _FTPDataSocket.Connected Then
            While (True)
                Array.Clear(_Buffer, 0, _BufferSize)
                _BytesRead = _FTPDataSocket.Receive(_Buffer, _Buffer.Length, 0)
                _Data += ASCII.GetString(_Buffer, 0, _BytesRead)

                If (_BytesRead < _Buffer.Length) Then Exit While
            End While
        Else
            _ResponseData = "FTP data socket failed to connect."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - GetFileList subroutine failed - FTP data socket failed to connect.", "")
        End If

        Dim _Parts() As String = _Data.Split(_EndLine)

        ' Close and destroy the FTP data socket.
        If (_FTPDataSocket Is Nothing = False) Then
            _FTPDataSocket.Close()
            _FTPDataSocket = Nothing
        End If

        Return _Parts

    End Function

    '''<summary>
    ''' Public Function: GetFileSize - This function will get the size of a provided file name.
    '''</summary>
    '''<param name="fileName">As String</param>
    '''<returns>Function returns a Long.</returns>
    ' Get the size of the file on the FTP server.
    Public Function GetFileSize(ByVal fileName As String) As Long

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        Dim _FileSize As Long

        'Send an FTP SIZE command.
        SendCommand("SIZE ", fileName)
        _FileSize = 0

        Return _FileSize = Int64.Parse(_ResponseData.Substring(4))

    End Function

    '''<summary>
    ''' Public Sub: DownloadFile - This subroutine gets a specific file.
    '''<param name="fileName">As String</param>
    '''<param name="filePath">As String</param>
    '''<optional param name="fileResume">As Boolean</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub DownloadFile(ByVal fileName As String, ByVal filePath As String, Optional ByVal fileResume As Boolean = False)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        ' Set the FTP mode to binary.
        SetBinaryMode(True)

        ' Create an FTP data socket.
        Dim _FTPDataSocket As Socket = CreateDataSocket()

        ' Create a file.
        Dim _FileStream As Stream
        If (Not (File.Exists(filePath & fileName))) Then
            _FileStream = File.Create(filePath & fileName)
            _FileStream.Close()
        End If

        Dim _FTPFileStreamOutput As FileStream
        _FTPFileStreamOutput = New FileStream(filePath & fileName, FileMode.Open)

        If fileResume Then
            Dim _FileOffset As Long
            _FileOffset = _FTPFileStreamOutput.Length

            If (_FileOffset > 0) Then
                ' Send an FTP REST command to restart a file.
                SendCommand("REST ", _FileOffset)
                If (_ResponseCode <> 350) Then
                    'The FTP host does not support resuming.
                    _FileOffset = 0
                End If
            End If
            If (_FileOffset <> 0) Then
                _FTPFileStreamOutput.Seek(_FileOffset, SeekOrigin.Begin)
            End If
        End If

        'Send an FTP RETR command to retrieve a file.
        SendCommand("RETR ", fileName)

        Const _EndLine As Char = "\n"
        Const _BufferSize As Integer = 512

        Dim _Data As String = ""
        Dim _Buffer(_BufferSize) As Byte
        Dim _BytesRead As Integer = 0

        If _FTPDataSocket.Connected Then
            While (True)
                Array.Clear(_Buffer, 0, _BufferSize)
                _BytesRead = _FTPDataSocket.Receive(_Buffer, _Buffer.Length, 0)
                _FTPFileStreamOutput.Write(_Buffer, 0, _BytesRead)

                If (_BytesRead < _Buffer.Length) Then Exit While
            End While
        Else
            _ResponseData = "FTP data socket failed to connect."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - GetFile subroutine failed - FTP data socket failed to connect.", "")
        End If

        _FTPFileStreamOutput.Close()

        ' Close and destroy the FTP data socket.
        If (_FTPDataSocket Is Nothing = False) Then
            _FTPDataSocket.Close()
            _FTPDataSocket = Nothing
        End If

    End Sub

    '''<summary>
    ''' Public Sub: UploadFile - This subroutine uploads a specific file to an FTP host.
    '''<param name="fileName">As String</param>
    '''<param name="filePath">As String</param>
    '''<optional param name="fileResume">As Boolean</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub UploadFile(ByVal fileName As String, ByVal filePath As String, Optional ByVal fileResume As Boolean = False)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        ' Set the FTP mode to binary.
        SetBinaryMode(True)

        ' Create an FTP data socket.
        Dim _FTPDataSocket As Socket = CreateDataSocket()

        ' Check to see if the file exists locally before the upload.
        If (File.Exists(filePath & fileName)) Then

            ' Open the input stream to read the source file.
            Dim _FTPFileStreamInput As FileStream
            _FTPFileStreamInput = New FileStream(filePath & fileName, FileMode.Open)

            If fileResume Then
                ' Check to see if part of the file has already been uploaded.
                Dim _FileOffset As Long
                _FileOffset = 0

                Try
                    _FileOffset = GetFileSize(fileName)
                Catch ex As Exception
                    _FileOffset = 0
                End Try

                If (_FileOffset > 0) Then
                    ' Send an FTP REST command to restart a file.
                    SendCommand("REST ", _FileOffset)
                    If (_ResponseCode <> 350) Then
                        'The FTP host does not support resuming.
                        _FileOffset = 0
                    End If
                End If

                If (_FileOffset <> 0) Then
                    _FTPFileStreamInput.Seek(_FileOffset, SeekOrigin.Begin)
                End If
            End If

            ' Send an FTP STOR command to store a file.
            SendCommand("STOR ", fileName)

            ' Upload the file.
            Const _BufferSize As Integer = 512
            Dim _Buffer(_BufferSize) As Byte
            Dim _BytesRead As Integer = 0

            _BytesRead = _FTPFileStreamInput.Read(_Buffer, 0, _Buffer.Length)
            If _FTPDataSocket.Connected Then
                While (_BytesRead > 0)
                    _FTPDataSocket.Send(_Buffer, _BytesRead, 0)
                    _BytesRead = _FTPFileStreamInput.Read(_Buffer, 0, _Buffer.Length)
                End While
               
            Else
                    _ResponseData = "FTP data socket failed to connect."
                    ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - UploadFile subroutine failed - FTP data socket failed to connect.", "")
            End If
            _FTPFileStreamInput.Close()

        Else
            _ResponseData = "File to upload does not exist on local machine."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - UploadFile subroutine failed - file to upload does not exist on local machine.", "")
        End If

        ' Close and destroy the FTP data socket.
        If (_FTPDataSocket Is Nothing = False) Then
            _FTPDataSocket.Close()
            _FTPDataSocket = Nothing
        End If

    End Sub

    '''<summary>
    ''' Public Sub: UploadFile - This subroutine deletes a specific file on an FTP host.
    '''<param name="fileName">As String</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub DeleteFile(ByVal fileName As String)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        ' Send an FTP DELE command to delete a file.
        SendCommand("DELE ", fileName)

    End Sub

    '''<summary>
    ''' Public Sub: RenameFile - This subroutine renames a specific file on an FTP host.
    '''<param name="fileName">As String</param>
    '''<param name="fileNewName">As String</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub RenameFile(ByVal fileName As String, ByVal fileNewName As String)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        ' Send an FTP RNFR command to select a file to be renamed.
        SendCommand("RNFR ", fileName)

        'Send an FTP RNTO command to rename the selected file to a new file name.
        SendCommand("RNTO ", fileNewName)

    End Sub

    '''<summary>
    ''' Public Sub: GetDirectory - This subroutine gets the current directory on an FTP host.
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub GetDirectory()

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        'Send an FTP CWD command to change to a directory.
        SendCommand("PWD ", "")

    End Sub

    '''<summary>
    ''' Public Sub: ChangeDirectory - This subroutine changes to a directory on an FTP host.
    '''<param name="directoryName">As String</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub ChangeDirectory(ByVal directoryName As String)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        'Check if in the root directory.
        If (directoryName.Equals(".")) Then
            Exit Sub
        End If

        'Send an FTP CWD command to change to a directory.
        SendCommand("CWD ", directoryName)

    End Sub

    '''<summary>
    ''' Public Sub: CreateDirectory - This subroutine creates a new directory on an FTP host.
    '''<param name="directoryName">As String</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub CreateDirectory(ByVal directoryName As String)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        'Send an FTP MKD command to make a new directory.
        SendCommand("MKD ", directoryName)

    End Sub

    '''<summary>
    ''' Public Sub: RemoveDirectory - This subroutine removes a directory on an FTP host.
    '''<param name="directoryName">As String</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub RemoveDirectory(ByVal directoryName As String)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        'Send an FTP RMD command to remove a directory.
        SendCommand("RMD ", directoryName)

    End Sub

#End Region

#Region "Private Methods"

    '''<summary>
    ''' Private Sub: CreateCommandSocket - Provided a Host and a port this subroutine will instantiate an FTP command socket.
    '''</summary>
    '''<returns>Subroutine returns nothing.</returns>
    Private Sub CreateCommandSocket()

        ' Create the FTP command socket.
        _FTPCommandSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

        Try
            Dim HostMachine As IPEndPoint = New IPEndPoint(Dns.Resolve(_Host).AddressList(0), _Port)
            Try
                ' Connect the FTP command socket to the FTP host machine.
                _FTPCommandSocket.Connect(HostMachine)
            Catch ex As Exception
                ' Connection could not be opened due to malformed connection.
                _ResponseData = "FTP Command Socket Connection Could Not Be Established."
                ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Command Socket Connection Could Not Be Established.", ex)
            End Try
        Catch ex As Exception
            ' Connection could not be opened because DNS cannot resolve the host IP.
            _ResponseData = "FTP Command Socket Connection Could Not Be Established. Connection could not be opened because DNS cannot resolve the host IP."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Command Socket Connection Could Not Be Established. DNS cannot resolve the FTP host.", ex)
        End Try
        _ResponseData = "FTP Command Socket Connection Established."
        ReadResponse()

    End Sub

    '''<summary>
    ''' Private Function: CreateDataSocket - Provided that a PASV command has been sent to the host, this function returns
    ''' an FTP data socket.
    '''</summary>
    '''<returns>Subroutine returns nothing.</returns>
    Private Function CreateDataSocket() As Socket

        Dim _FTPDataSocket As Socket
        Dim _FTPHostIPFrontBracket As Integer
        Dim _FTPHostIPBackBracket As Integer
        Dim _FTPHostIPData As String
        Dim _FTPHostIPLength As Integer
        Dim _FTPHostIPPartCount As Integer
        Dim _FTPHostIPParts(6) As Integer
        Dim _FTPHostIPCharater As Char
        Dim _Buffer As String
        Dim _Counter As Integer

        'Send an FTP PASV command to use passive data connection.
        SendCommand("PASV", "")

        _FTPHostIPFrontBracket = _ResponseData.IndexOf("(")
        _FTPHostIPBackBracket = _ResponseData.IndexOf(")")
        _FTPHostIPData = _ResponseData.Substring(_FTPHostIPFrontBracket + 1, _FTPHostIPBackBracket - _FTPHostIPFrontBracket - 1)

        _FTPHostIPLength = _FTPHostIPData.Length
        _FTPHostIPPartCount = 0
        _Buffer = ""

        For _Counter = 0 To ((_FTPHostIPLength - 1) And _FTPHostIPPartCount <= 6)
            _FTPHostIPCharater = Char.Parse(_FTPHostIPData.Substring(_Counter, 1))
            If (Char.IsDigit(_FTPHostIPCharater)) Then
                _Buffer += _FTPHostIPCharater
            ElseIf (_FTPHostIPCharater <> ",") Then
                ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Host did not accept the PASV command.", "")
            End If

            If ((_FTPHostIPCharater = ",") Or (_Counter + 1 = _FTPHostIPLength)) Then
                Try
                    _FTPHostIPParts(_FTPHostIPPartCount) = Int32.Parse(_Buffer)
                    _FTPHostIPPartCount += 1
                    _Buffer = ""
                Catch ex As Exception
                    ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Host did not accept the PASV command.", ex)
                End Try
            End If
        Next

        ' Create the data host.
        Dim _DataHost As String = _FTPHostIPParts(0) & "." & _FTPHostIPParts(1) & "." & _FTPHostIPParts(2) & "." & _FTPHostIPParts(3)

        ' Create the data port.
        Dim _DataPort As Integer = _FTPHostIPParts(4) << 8

        ' Determine the data port number.
        _DataPort = _DataPort + _FTPHostIPParts(5)

        ' Create the FTP data socket from the data host and data port.
        _FTPDataSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

        Try
            Dim HostMachine As IPEndPoint = New IPEndPoint(Dns.Resolve(_DataHost).AddressList(0), _DataPort)
            Try
                ' Connect the FTP data socket to the FTP host machine.
                _FTPDataSocket.Connect(HostMachine)
                Return _FTPDataSocket
            Catch ex As Exception
                ' Connection could not be opened due to malformed connection.
                _ResponseData = "FTP Data Socket Connection Could Not Be Established."
                ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Data Socket Connection Could Not Be Established.", ex)
            End Try
        Catch ex As Exception
            ' Connection could not be opened because DNS cannot resolve the host IP.
            _ResponseData = "FTP Data Socket Connection Could Not Be Established. Connection could not be opened because DNS cannot resolve the host IP."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Data Socket Connection Could Not Be Established. DNS cannot resolve the FTP host.", ex)
        End Try
        _ResponseData = "FTP Data Socket Connection Established."

    End Function

    '''<summary>
    ''' Private Sub: ReadResponse - This subroutine will read line by line the reply to
    ''' a command sent to an FTP host.
    '''</summary>
    '''<returns>Function returns a string.</returns>
    Private Sub ReadResponse()

        ' Read the response from the FTP host.
        _ResponseData = ReadLine(False)
        _ResponseCode = Int32.Parse(_ResponseData.Substring(0, 3))

    End Sub

    '''<summary>
    ''' Private Function: ReadLine - This function handles the actual reading of the FTP host reply.
    '''</summary>
    '''<param name="clearResponse">As Boolean</param>
    '''<returns>Function returns a string.</returns>
    Private Function ReadLine(ByVal clearResponse As Boolean) As String

        Const _EndLine As Char = "\n"
        Const _BufferSize As Integer = 512

        Dim _Data As String = ""
        Dim _Buffer(_BufferSize) As Byte
        Dim _BytesRead As Integer = 0

        If (clearResponse = True) Then _ResponseData = String.Empty

        While (True)
            Array.Clear(_Buffer, 0, _BufferSize)
            _BytesRead = _FTPCommandSocket.Receive(_Buffer, _Buffer.Length, 0)
            _Data += ASCII.GetString(_Buffer, 0, _BytesRead)

            If (_BytesRead < _Buffer.Length) Then Exit While
        End While

        Dim _Parts() As String = _Data.Split(_EndLine)

        If (_Parts.Length > 2) Then
            _ResponseData = _Parts(_Parts.Length - 2)
        Else
            _ResponseData = _Parts(0)
        End If

        If (_ResponseData.Substring(3, 1).Equals(" ") = False) Then
            Return ReadLine(False)
        End If

        Return _ResponseData
    End Function

#End Region

End Class

0
jjadde13
3/22/2006 8:19:52 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

1 Replies
1157 Views

Similar Articles

[PageSpeed] 13

All I made a bonehead mistake.  
Basically I have my subroutine for sending commands called SendCommand.
In that sub I take care of adding the space character after the command
before the command arguements. Well I really should have cleaned up
that sub to make it more efficient. Basically not all FTP commands have
arguements so I really shouldn't being adding that space unless there
are arguements. To make matters even more fun, in all my subroutines
thereafter I added a space after the FTP command and then shipped it to
the SendCommand sub which was already messed up, thus actually doubling
the space character between the FTP command and the FTP command
arguements if there were arguements. Somehow Windows based FTP servers
let this fly whereas Unix FTP servers cannot even understand what was
sent to it as a command. The fixed code that is working across the
board is below. There isn't much it doesn't do. I should probably add
events and a lot more error checking, but it will do for now:

Imports System
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Text.ASCIIEncoding
Imports System.Net.Sockets
Imports System.Configuration
Imports System.Resources

Public Class FTPClient

#Region "Local Properties"

    '''<summary>
    ''' Public Property: Host - String variable.
    '''</summary>
    Public Property Host() As String
        Get
            Return _Host
        End Get
        Set(ByVal Value As String)
            _Host = Value
        End Set
    End Property

    '''<summary>
    ''' Public Property: Path - String variable.
    '''</summary>
    Public Property Path() As String
        Get
            Return _Path
        End Get
        Set(ByVal Value As String)
            _Path = Value
        End Set
    End Property

    '''<summary>
    ''' Public Property: User - String variable.
    '''</summary>
    Public Property User() As String
        Get
            Return _User
        End Get
        Set(ByVal Value As String)
            _User = Value
        End Set
    End Property

    '''<summary>
    ''' Public Property: Password - String variable.
    '''</summary>
    Public Property Password() As String
        Get
            Return _Password
        End Get
        Set(ByVal Value As String)
            _Password = Value
        End Set
    End Property

    '''<summary>
    ''' Public Property: Port - String variable.
    '''</summary>
    Public Property Port() As String
        Get
            Return _Port
        End Get
        Set(ByVal Value As String)
            _Port = Value
        End Set
    End Property

    '''<summary>
    ''' Public ReadOnly Property: ResponseCode - String variable.
    '''</summary>
    Public ReadOnly Property ResponseCode() As String
        Get
            Return _ResponseCode
        End Get
    End Property

    '''<summary>
    ''' Public ReadOnly Property: ResponseData - String variable.
    '''</summary>
    Public ReadOnly Property ResponseData() As String
        Get
            Return _ResponseData
        End Get
    End Property

#End Region

    ' FTP Default Properties.
    Private _Host As String = "127.0.0.1"
    Private _Path As String = "."
    Private _User As String = "anonymous"
    Private _Password As String = "anonymous@nowhere.com"
    Private _Port As Integer = 21
    Private _ResponseCode As Integer
    Private _ResponseData As String
    Private _FTPCommandSocket As Socket = Nothing
    Private _FTPLogin As Boolean = False
    Private _FTPCommandSocketInstalled As Boolean = False

#Region "Public Methods"

    Public Sub New()

    End Sub

    '''<summary>
    ''' Public Function: Login - This function will create a command and data socket and then send the
    ''' login credentials to the FTP host. 
    '''</summary>
    '''<returns>Function returns a Boolean.</returns>
    Public Function Login() As Boolean

        ' Create an FTP command socket.
        CreateCommandSocket()

        ' Send the gathered login information to the FTP host.
        Try
            SendCommand("USER", _User)
            SendCommand("PASS", _Password)
            _FTPLogin = True
        Catch ex As Exception
            ' Login did not work because the FTP login information was not accepted.
            _ResponseData = "FTP Login function not executed."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP login information was not accepted", ex)
            Return False
        End Try

        ' Login successful.
        Return True

    End Function

    '''<summary>
    ''' Public Sub: Logout - This subroutine will disconnect and close an FTP command and data socket.
    '''</summary>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub Logout()

        ' Close and destroy the FTP command socket.
        If (_FTPCommandSocket Is Nothing = False) Then
            SendCommand("QUIT", "")
            _FTPCommandSocket.Close()
            _FTPCommandSocket = Nothing
        End If
    End Sub

    '''<summary>
    ''' Public Sub: SendCommand - Provided a Command and Arguements, this subroutine will execute an FTP Command.
    ''' Commands already taken care of with subroutines below:
    ''' TYPE:   Mode (ASCII or Binary)
    ''' NLST:   List files in directory
    ''' SIZE:   Get file Size
    ''' RETR:   Download a file
    ''' STOR:   Upload a file
    ''' DELE:   Delete a file
    ''' RNFR:   Select a file to be renamed
    ''' RNTO:   Rename a selected file
    ''' PWD:    Get a current directory
    ''' CWD:    Change directory
    ''' RDM:    Remove a directory
    '''</summary>
    '''<param name="FTPCommand">As String</param>
    '''<param name="FTPCommandArguements">As String</param>
    '''<returns>Function returns an FTP stream.</returns>
    Public Sub SendCommand(ByVal FTPCommand As String, ByVal FTPCommandArguments As String)

        Dim _FTPCommand As String
        ' Combine FTP command with the FTP command arguements.
        If FTPCommandArguments = String.Empty Then
            _FTPCommand = FTPCommand
        Else
            _FTPCommand = FTPCommand & " " & FTPCommandArguments
        End If
        _FTPCommand += Environment.NewLine

        ' Convert the FTP command into ASCII text.
        Dim commandBytes() As Byte = ASCII.GetBytes(_FTPCommand)

        Try
            ' Execute the FTP command on the FTP host.
            _FTPCommandSocket.Send(commandBytes, commandBytes.Length, 0)
            ReadResponse()
        Catch ex As Exception
            ' Command was not executed.
            _ResponseData = "FTP SendCommand subroutine not executed."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP command was not accepted", ex)
        End Try
    End Sub

    '''<summary>
    ''' Public Sub: SetBinaryMode - This subroutine sets the FTP mode to binary.
    '''<param name="mode">As Boolean</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub SetBinaryMode(ByVal mode As Boolean)

        If (mode) Then
            'Send the FTP TYPE command as binary.
            SendCommand("TYPE", "I")
        Else
            'Send the FTP TYPE command as ASCII.
            SendCommand("TYPE", "A")
        End If
    End Sub

    '''<summary>
    ''' Public Function: GetDirectoryFileList - This function will get the names of the files from the provided directory name.
    '''</summary>
    '''<param name="directoryName">As String</param>
    '''<returns>Function returns a string.</returns>
    Public Function GetFileList(ByVal directoryName As String) As String()

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        ' Create an FTP data socket.
        Dim _FTPDataSocket As Socket = CreateDataSocket()

        'Send an FTP NLST command.
        SendCommand("NLST", directoryName)

        Const _EndLine As Char = "\n"
        Const _BufferSize As Integer = 512

        Dim _Data As String = ""
        Dim _Buffer(_BufferSize) As Byte
        Dim _BytesRead As Integer = 0

        If _FTPDataSocket.Connected Then
            While (True)
                Array.Clear(_Buffer, 0, _BufferSize)
                _BytesRead = _FTPDataSocket.Receive(_Buffer, _Buffer.Length, 0)
                _Data += ASCII.GetString(_Buffer, 0, _BytesRead)

                If (_BytesRead < _Buffer.Length) Then Exit While
            End While
        Else
            _ResponseData = "FTP data socket failed to connect."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - GetFileList subroutine failed - FTP data socket failed to connect.", "")
        End If

        Dim _Parts() As String = _Data.Split(_EndLine)

        ' Close and destroy the FTP data socket.
        If (_FTPDataSocket Is Nothing = False) Then
            _FTPDataSocket.Close()
            _FTPDataSocket = Nothing
        End If

        Return _Parts

    End Function

    '''<summary>
    ''' Public Function: GetFileSize - This function will get the size of a provided file name.
    '''</summary>
    '''<param name="fileName">As String</param>
    '''<returns>Function returns a Long.</returns>
    ' Get the size of the file on the FTP server.
    Public Function GetFileSize(ByVal fileName As String) As Long

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        Dim _FileSize As Long

        'Send an FTP SIZE command.
        SendCommand("SIZE", fileName)
        _FileSize = 0

        Return _FileSize = Int64.Parse(_ResponseData.Substring(4))

    End Function

    '''<summary>
    ''' Public Sub: DownloadFile - This subroutine gets a specific file.
    '''<param name="fileName">As String</param>
    '''<param name="filePath">As String</param>
    '''<optional param name="fileResume">As Boolean</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub DownloadFile(ByVal fileName As String, ByVal filePath As String, Optional ByVal fileResume As Boolean = False)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        ' Set the FTP mode to binary.
        SetBinaryMode(True)

        ' Create an FTP data socket.
        Dim _FTPDataSocket As Socket = CreateDataSocket()

        ' Create a file.
        Dim _FileStream As Stream
        If (Not (File.Exists(filePath & fileName))) Then
            _FileStream = File.Create(filePath & fileName)
            _FileStream.Close()
        End If

        Dim _FTPFileStreamOutput As FileStream
        _FTPFileStreamOutput = New FileStream(filePath & fileName, FileMode.Open)

        If fileResume Then
            Dim _FileOffset As Long
            _FileOffset = _FTPFileStreamOutput.Length

            If (_FileOffset > 0) Then
                ' Send an FTP REST command to restart a file.
                SendCommand("REST", _FileOffset)
                If (_ResponseCode <> 350) Then
                    'The FTP host does not support resuming.
                    _FileOffset = 0
                End If
            End If
            If (_FileOffset <> 0) Then
                _FTPFileStreamOutput.Seek(_FileOffset, SeekOrigin.Begin)
            End If
        End If

        'Send an FTP RETR command to retrieve a file.
        SendCommand("RETR", fileName)

        Const _EndLine As Char = "\n"
        Const _BufferSize As Integer = 512

        Dim _Data As String = ""
        Dim _Buffer(_BufferSize) As Byte
        Dim _BytesRead As Integer = 0

        If _FTPDataSocket.Connected Then
            While (True)
                Array.Clear(_Buffer, 0, _BufferSize)
                _BytesRead = _FTPDataSocket.Receive(_Buffer, _Buffer.Length, 0)
                _FTPFileStreamOutput.Write(_Buffer, 0, _BytesRead)

                If (_BytesRead < _Buffer.Length) Then Exit While
            End While
        Else
            _ResponseData = "FTP data socket failed to connect."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - GetFile subroutine failed - FTP data socket failed to connect.", "")
        End If

        _FTPFileStreamOutput.Close()

        ' Close and destroy the FTP data socket.
        If (_FTPDataSocket Is Nothing = False) Then
            _FTPDataSocket.Close()
            _FTPDataSocket = Nothing
        End If

    End Sub

    '''<summary>
    ''' Public Sub: UploadFile - This subroutine uploads a specific file to an FTP host.
    '''<param name="fileName">As String</param>
    '''<param name="filePath">As String</param>
    '''<optional param name="fileResume">As Boolean</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub UploadFile(ByVal fileName As String, ByVal filePath As String, Optional ByVal fileResume As Boolean = False)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        ' Set the FTP mode to binary.
        SetBinaryMode(True)

        ' Create an FTP data socket.
        Dim _FTPDataSocket As Socket = CreateDataSocket()

        ' Check to see if the file exists locally before the upload.
        If (File.Exists(filePath & fileName)) Then

            ' Open the input stream to read the source file.
            Dim _FTPFileStreamInput As FileStream
            _FTPFileStreamInput = New FileStream(filePath & fileName, FileMode.Open)

            If fileResume Then
                ' Check to see if part of the file has already been uploaded.
                Dim _FileOffset As Long
                _FileOffset = 0

                Try
                    _FileOffset = GetFileSize(fileName)
                Catch ex As Exception
                    _FileOffset = 0
                End Try

                If (_FileOffset > 0) Then
                    ' Send an FTP REST command to restart a file.
                    SendCommand("REST", _FileOffset)
                    If (_ResponseCode <> 350) Then
                        'The FTP host does not support resuming.
                        _FileOffset = 0
                    End If
                End If

                If (_FileOffset <> 0) Then
                    _FTPFileStreamInput.Seek(_FileOffset, SeekOrigin.Begin)
                End If
            End If

            ' Send an FTP STOR command to store a file.
            SendCommand("STOR", fileName)

            ' Upload the file.
            Const _BufferSize As Integer = 512
            Dim _Buffer(_BufferSize) As Byte
            Dim _BytesRead As Integer = 0

            _BytesRead = _FTPFileStreamInput.Read(_Buffer, 0, _Buffer.Length)
            If _FTPDataSocket.Connected Then
                While (_BytesRead > 0)
                    _FTPDataSocket.Send(_Buffer, _BytesRead, 0)
                    _BytesRead = _FTPFileStreamInput.Read(_Buffer, 0, _Buffer.Length)
                End While
               
            Else
                    _ResponseData = "FTP data socket failed to connect."
                    ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - UploadFile subroutine failed - FTP data socket failed to connect.", "")
            End If
            _FTPFileStreamInput.Close()

        Else
            _ResponseData = "File to upload does not exist on local machine."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - UploadFile subroutine failed - file to upload does not exist on local machine.", "")
        End If

        ' Close and destroy the FTP data socket.
        If (_FTPDataSocket Is Nothing = False) Then
            _FTPDataSocket.Close()
            _FTPDataSocket = Nothing
        End If

    End Sub

    '''<summary>
    ''' Public Sub: UploadFile - This subroutine deletes a specific file on an FTP host.
    '''<param name="fileName">As String</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub DeleteFile(ByVal fileName As String)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        ' Send an FTP DELE command to delete a file.
        SendCommand("DELE", fileName)

    End Sub

    '''<summary>
    ''' Public Sub: RenameFile - This subroutine renames a specific file on an FTP host.
    '''<param name="fileName">As String</param>
    '''<param name="fileNewName">As String</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub RenameFile(ByVal fileName As String, ByVal fileNewName As String)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        ' Send an FTP RNFR command to select a file to be renamed.
        SendCommand("RNFR", fileName)

        'Send an FTP RNTO command to rename the selected file to a new file name.
        SendCommand("RNTO", fileNewName)

    End Sub

    '''<summary>
    ''' Public Sub: GetDirectory - This subroutine gets the current directory on an FTP host.
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub GetDirectory()

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        'Send an FTP CWD command to change to a directory.
        SendCommand("PWD", "")

    End Sub

    '''<summary>
    ''' Public Sub: ChangeDirectory - This subroutine changes to a directory on an FTP host.
    '''<param name="directoryName">As String</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub ChangeDirectory(ByVal directoryName As String)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        'Check if in the root directory.
        If (directoryName.Equals(".")) Then
            Exit Sub
        End If

        'Send an FTP CWD command to change to a directory.
        SendCommand("CWD", directoryName)

    End Sub

    '''<summary>
    ''' Public Sub: CreateDirectory - This subroutine creates a new directory on an FTP host.
    '''<param name="directoryName">As String</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub CreateDirectory(ByVal directoryName As String)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        'Send an FTP MKD command to make a new directory.
        SendCommand("MKD", directoryName)

    End Sub

    '''<summary>
    ''' Public Sub: RemoveDirectory - This subroutine removes a directory on an FTP host.
    '''<param name="directoryName">As String</param>
    '''<returns>Subroutine returns nothing.</returns>
    Public Sub RemoveDirectory(ByVal directoryName As String)

        ' Check to see if user is logged into FTP host.
        If Not _FTPLogin Then
            Login()
        End If

        'Send an FTP RMD command to remove a directory.
        SendCommand("RMD", directoryName)

    End Sub

#End Region

#Region "Private Methods"

    '''<summary>
    ''' Private Sub: CreateCommandSocket - Provided a Host and a port this subroutine will instantiate an FTP command socket.
    '''</summary>
    '''<returns>Subroutine returns nothing.</returns>
    Private Sub CreateCommandSocket()

        ' Create the FTP command socket.
        _FTPCommandSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

        Try
            Dim HostMachine As IPEndPoint = New IPEndPoint(Dns.Resolve(_Host).AddressList(0), _Port)
            Try
                ' Connect the FTP command socket to the FTP host machine.
                _FTPCommandSocket.Connect(HostMachine)
            Catch ex As Exception
                ' Connection could not be opened due to malformed connection.
                _ResponseData = "FTP Command Socket Connection Could Not Be Established."
                ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Command Socket Connection Could Not Be Established.", ex)
            End Try
        Catch ex As Exception
            ' Connection could not be opened because DNS cannot resolve the host IP.
            _ResponseData = "FTP Command Socket Connection Could Not Be Established. Connection could not be opened because DNS cannot resolve the host IP."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Command Socket Connection Could Not Be Established. DNS cannot resolve the FTP host.", ex)
        End Try
        _ResponseData = "FTP Command Socket Connection Established."
        ReadResponse()

    End Sub

    '''<summary>
    ''' Private Function: CreateDataSocket - Provided that a PASV command has been sent to the host, this function returns
    ''' an FTP data socket.
    '''</summary>
    '''<returns>Subroutine returns nothing.</returns>
    Private Function CreateDataSocket() As Socket

        Dim _FTPDataSocket As Socket
        Dim _FTPHostIPFrontBracket As Integer
        Dim _FTPHostIPBackBracket As Integer
        Dim _FTPHostIPData As String
        Dim _FTPHostIPLength As Integer
        Dim _FTPHostIPPartCount As Integer
        Dim _FTPHostIPParts(6) As Integer
        Dim _FTPHostIPCharater As Char
        Dim _Buffer As String
        Dim _Counter As Integer

        'Send an FTP PASV command to use passive data connection.
        SendCommand("PASV", "")

        _FTPHostIPFrontBracket = _ResponseData.IndexOf("(")
        _FTPHostIPBackBracket = _ResponseData.IndexOf(")")
        _FTPHostIPData = _ResponseData.Substring(_FTPHostIPFrontBracket + 1, _FTPHostIPBackBracket - _FTPHostIPFrontBracket - 1)

        _FTPHostIPLength = _FTPHostIPData.Length
        _FTPHostIPPartCount = 0
        _Buffer = ""

        For _Counter = 0 To ((_FTPHostIPLength - 1) And _FTPHostIPPartCount <= 6)
            _FTPHostIPCharater = Char.Parse(_FTPHostIPData.Substring(_Counter, 1))
            If (Char.IsDigit(_FTPHostIPCharater)) Then
                _Buffer += _FTPHostIPCharater
            ElseIf (_FTPHostIPCharater <> ",") Then
                ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Host did not accept the PASV command.", "")
            End If

            If ((_FTPHostIPCharater = ",") Or (_Counter + 1 = _FTPHostIPLength)) Then
                Try
                    _FTPHostIPParts(_FTPHostIPPartCount) = Int32.Parse(_Buffer)
                    _FTPHostIPPartCount += 1
                    _Buffer = ""
                Catch ex As Exception
                    ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Host did not accept the PASV command.", ex)
                End Try
            End If
        Next

        ' Create the data host.
        Dim _DataHost As String = _FTPHostIPParts(0) & "." & _FTPHostIPParts(1) & "." & _FTPHostIPParts(2) & "." & _FTPHostIPParts(3)

        ' Create the data port.
        Dim _DataPort As Integer = _FTPHostIPParts(4) << 8

        ' Determine the data port number.
        _DataPort = _DataPort + _FTPHostIPParts(5)

        ' Create the FTP data socket from the data host and data port.
        _FTPDataSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

        Try
            Dim HostMachine As IPEndPoint = New IPEndPoint(Dns.Resolve(_DataHost).AddressList(0), _DataPort)
            Try
                ' Connect the FTP data socket to the FTP host machine.
                _FTPDataSocket.Connect(HostMachine)
                Return _FTPDataSocket
            Catch ex As Exception
                ' Connection could not be opened due to malformed connection.
                _ResponseData = "FTP Data Socket Connection Could Not Be Established."
                ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Data Socket Connection Could Not Be Established.", ex)
            End Try
        Catch ex As Exception
            ' Connection could not be opened because DNS cannot resolve the host IP.
            _ResponseData = "FTP Data Socket Connection Could Not Be Established. Connection could not be opened because DNS cannot resolve the host IP."
            ' Throw New MPException(AppSettings.Item("Project"), "MP.IT.Web.Library.FTP - FTP Data Socket Connection Could Not Be Established. DNS cannot resolve the FTP host.", ex)
        End Try
        _ResponseData = "FTP Data Socket Connection Established."

    End Function

    '''<summary>
    ''' Private Sub: ReadResponse - This subroutine will read line by line the reply to
    ''' a command sent to an FTP host.
    '''</summary>
    '''<returns>Function returns a string.</returns>
    Private Sub ReadResponse()

        ' Read the response from the FTP host.
        _ResponseData = ReadLine(False)
        _ResponseCode = Int32.Parse(_ResponseData.Substring(0, 3))

    End Sub

    '''<summary>
    ''' Private Function: ReadLine - This function handles the actual reading of the FTP host reply.
    '''</summary>
    '''<param name="clearResponse">As Boolean</param>
    '''<returns>Function returns a string.</returns>
    Private Function ReadLine(ByVal clearResponse As Boolean) As String

        Const _EndLine As Char = "\n"
        Const _BufferSize As Integer = 512

        Dim _Data As String = ""
        Dim _Buffer(_BufferSize) As Byte
        Dim _BytesRead As Integer = 0

        If (clearResponse = True) Then _ResponseData = String.Empty

        While (True)
            Array.Clear(_Buffer, 0, _BufferSize)
            _BytesRead = _FTPCommandSocket.Receive(_Buffer, _Buffer.Length, 0)
            _Data += ASCII.GetString(_Buffer, 0, _BytesRead)

            If (_BytesRead < _Buffer.Length) Then Exit While
        End While

        Dim _Parts() As String = _Data.Split(_EndLine)

        If (_Parts.Length > 2) Then
            _ResponseData = _Parts(_Parts.Length - 2)
        Else
            _ResponseData = _Parts(0)
        End If

        If (_ResponseData.Substring(3, 1).Equals(" ") = False) Then
            Return ReadLine(False)
        End If

        Return _ResponseData
    End Function

#End Region

End Class

0
jjadde13
3/22/2006 10:10:58 PM
Reply:

Similar Artilces:

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

converting to vb.net from c#.net authorize.net
authorize.net offered me some sample code when I signed up with them the only problem is the sample code is in c#.net but my page that they type all of their credit card into is vb.net <code><%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <script language="C#" runat="server"> void Page_Load(Object Src, EventArgs E) { myPage.Text = readHtmlPage("https://certification.authorize.net/gateway/transact.dll"); } private String readHtmlPage(string url) { ...

Upgrade VB.net 2002 to VB.net 2003
Hi, i want to upgrade VB.net 2002 to VB.net 2003.what is the procedure?Uninstall 2002 and Install 2003 or something else? VB.net 2003 includes Framework 1.1 or i will install it separately?thanx in advance ...

How to get RS (From VB6) to .NET (VB.NET)
Hi Friends,         I have requirement, there is one function in VB6 it returns a RS, I need to call that function in  VB.NET, how to get those values into .NET, if can any body can help (pass me some code snippets), that will be greate, Thank you.Madhu... -Madhu hey guys i got this one just by using fill method.-Madhu...

vb.net vs c#.net vs j#.net
just out of curiousity which looks, acts most like java? i'm still learning trying to used to vb.net but it seems that it was easier to do some stuff with java. C# is Java++ in my opinion. If you have done C or Jave you will prefer C#.Mike Schellenberger - MCAD If you are looking for language similar to java go for J#. However most code samples you find on the net will be in VB.NET and C#....

converting vb.net 2003 files to vb.net 2005
Hi, i am beginner..i watch videos about vb.net..they made on vs.net 2003 when i wrote these codes in 2005 ,it gives errors..is there any program which convert the code automatically?   thanks,Thanks,Speranza What videos are you talking about?  There are lots of great, up-to-date ASP.NET Videos on this site for free.Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! i am talking about learnvisualstudio.net videos..Thanks,Speranza Speranza:they made on vs.net 2003 when i wrote these codes in 2005 ,it gives errors..is there a...

ANN: VB.NET Forums
Hello Fellow Programmers: Just an announcement the VB.NET Forums moved to the advanced vBulletin 3 software providing a feature rich and enjoyable forum experience. Stop by in your Internet surfing to help others, ask questions, and partake in our VB.NET only community. Visit us in addition to your trips to this great community. http://www.vbdotnetforums.comNeal...

ftp in vb.net
please anybody put the source code for uploading the file from remote host to our server in vb.net Thank you.nothing ever changes just rearranges http://www.developer.com/net/vb/article.php/10926_3424121_2 might be a startArticles and news on ASP/ASP.NETASPCode.net thanks buddynothing ever changes just rearranges...

VB.Net To C#.Net
Hello... Since Last from 1 year i had develope web application in using vb.net now i want to transfer from vb.net to c#.net so what should i do to transform to c# language any link or book related to me through i can easily understand and coding using c# in a short time... Thanks~ Mark As Answer If UseFull ~Kaushal. Hi, you can read the specifications of the language. You're already familiar with .NET and how to program in an OO manner thanks to your experience with vb.net. The only thing you need to learn is the new syntax of C#. You can also convert parts of your v...

Net:FTP, Net::Cmd
I'm using Net::FTp and Net::Cmd modules in a script to completely automate some FTPing stuff. snippet $ftp->put($fileh,"/tmp/test.txt") || die "cant put the file\n"; $ftp->command("chmod","755","test.txt") || die "Cant run quot\n"; $ftp->quit(); I have no luck making the $ftp->command stuff to work. I'm using solaris 5.8 ftp client. Anyway, I can make this work? Native Solaris ftp client/server can not support "quot site" stuff. Am I out of luck?? Please dont offer suggestions to use &...

vb .net or c# .net
I currently develop websites using php but have been requested to develop a site using asp.net. The question I have is for someone who knows php would it be better to transition to vb.net or c#.net? Thanks, Fr. Robert C# -> There is a converter that will transition about 60% or more of your PHP code to C#. Plus C# is closer to PHP than VB.NET.Jason N. GaylordASPInsider and Microsoft MVPhttp://jasongaylord.com...

Net::SSH and Net::FTP?
------_=_NextPart_001_01C3B7DF.20E3F54A Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I would like to use SSH to login to a remote system, then using FTP, upload a file from the remote machine to another machine which will display the data. If I can automate this process, I think I'll be in great shape, tell me does this code seem like it would work for this? >use Net::SSH::Perl;=20 >my $ssh =3D Net::SSH::Perl->new($host); #Logging into the remote = machine >$ssh->login;=20 >my($READ, $WRITE) =3D $ssh-&...

C#.NET or VB.NET
what lang does everyone prefer? Thanks, Peter Iuvara, MCP It's a very famous debatable question in forums! I would say if you are from Java/C/C++, then C# would be easy to use for you. If you are from ASP/VB, then VB.NET would be easy for you! As long as if you follow CLS, then what ever the language you use, it's going to be the same for CLR!Sreedharhttp://www.w3coder.orgweblog http://weblogs.asp.net/skoganti I would agree with that ... just curious as to what user's on this forum predominantly code in?Thanks, Peter Iuvara, MCP I came from no real programming background, started i...

About VB.net And VC.net
I am always Programming With VB.net Recently My Teacher ask us to learn Vc or VC.net. I try to learn it and compare it with vb.net, I found it's much too complex than vb. However it is said vc is strongger than vb I want to know Why vc is strongger than vb? and is it hard too learn vc? I am new to asp.net Thanks for man who want to help me! Wuhan, Hubei, China Below links could give some info http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q308470Sreedharhttp://www.w3coder.orgweblog http://weblogs.asp.net/skoganti VisualC is not a language in an of itself...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

Web resources about - VB.NET - Issues with VB.NET FTP Class to UNIX FTP Server - asp.net.getting-started

Sports Illustrated Swimsuit Issue - Wikipedia, the free encyclopedia
Through the years many models, such as Cheryl Tiegs , Christie Brinkley , Paulina Porizkova , Elle Macpherson , Rachel Hunter , Rebecca Romijn ...

Potential Post-IPO Issues For Facebook: Mobile Revenue, Overvaluation, Google AdSense
The road ahead may be rough for Facebook, post- initial public offering . At least that is the speculation of Michael Mothner, founder and chief ...

The Lowdown: Big, Old Brands Battle the Trust Issue
The Lowdown is Ad Age's weekly look at news nuggets from across the world of marketing, including trends, campaign tidbits, executive comings ...

Climate Change Shouldn't Be A Partisan Issue But It Is
Why is young fogey Marco Rubio such a willfully ignorant science denier? Yesterday we talked about the passage of Fred Upton's disastrous anti-climate ...

VW Claims Carbon Dioxide Emission Issue Only Affects 36,000 Vehicles, Not 800,000
... may have issues with carbon dioxide emissions resulting in inflated fuel efficiency. But now, the carmaker says its was all just a big misunderstanding: ...

Cleveland Browns Coach Says Johnny Manziel Has ‘Deep-Rooted’ Issues
Cleveland Browns Coach Says Johnny Manziel Has ‘Deep-Rooted’ Issues

IRS Issues Guidance On Certain Student Loan Discharges
The IRS recently issued Revenue Procedure 2015-57, which addresses certain student loan discharges under the Department of Education’s Closed ...

Beijing Issues First-Ever Smog Red Alert
Beijing’s weather report via the AP: Smog smog smog smog smog smog smog smog . Read more...

Chipotle Shares Fall Amid E. Coli, Sales Issues
Chipotle's stock edged lower in midday trading Tuesday as the Mexican food chain continues to deal with fallout from an E. coli outbreak and ...


Resources last updated: 12/10/2015 1:54:57 AM