a_jam_sandwich
Well-known member
Currently im trying to write an FTP class but have run into problems. The below code connects to the server and gets the welcome message after that nothing yarda so I have no idea
see code below.
If anyone can figuar this out that would be great
Cheers
Andy
see code below.
Code:
Imports System.Net
Imports System.Net.Sockets
Imports System.Text.Encoding
Module ModFTPClass
Public Class classMyFTP
Private _username As String = "anonymous"
Private _password As String = ""
Private _ip As String = ""
Private _ISCONNECTED As Boolean = False
Private FTP_Socket As New TcpClient
Private FTP_networkStream As NetworkStream
Public Event onError(ByVal ErrorMessage As String)
Public Function Connect() As Boolean
If OpenConnection() Then
ReceiveCommand()
SendCommand("USER " & _username)
ReceiveCommand()
SendCommand("PASS " & _password)
ReceiveCommand()
SendCommand("LS www")
ReceiveCommand()
End If
End Function
Private Function OpenConnection() As Boolean
Try
FTP_Socket.Connect("ftp.microsoft.com", 21)
FTP_networkStream = FTP_Socket.GetStream()
_ISCONNECTED = True
Return True
Catch ex As Exception
RaiseEvent onError(ex.Message.ToString)
Return False
End Try
End Function
Private Function SendCommand(ByVal UserCommand As String)
If _ISCONNECTED Then
Dim MyCommand As Byte() = ASCII.GetBytes(UserCommand & vbCrLf)
FTP_networkStream.Write(MyCommand, 0, MyCommand.Length)
End If
End Function
Private Function ReceiveCommand() As String
If _ISCONNECTED Then
If FTP_networkStream.CanRead Then
Dim MyCommand(1024) As Byte
Dim BytesRead As Integer = 1
Dim ReceivedCommand As String
Dim Starttime As Long = Environment.TickCount
Do
BytesRead = FTP_networkStream.Read(MyCommand, 0, 1024)
Console.WriteLine(BytesRead)
ReceivedCommand += ASCII.GetChars(MyCommand)
Loop While FTP_networkStream.DataAvailable
Console.WriteLine(ReceivedCommand)
End If
End If
End Function
End Class
End Module
If anyone can figuar this out that would be great
Cheers
Andy