Private Sub ftp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ftp.Click
fileupload.SendFile("192.168.10.100", "test.txt", "username", "pwd", "f:\ftp.txt")
End Sub
Module fileupload
Private bytWriting As [Byte]()
Private bytReading As Byte()
Dim strAddress As String
Dim strFtpIP As String
Dim intPort As Integer
Public Function SendFile(ByVal strFtpIP As String, _
ByVal strSaveAs As String, ByVal strUsername As String, _
ByVal strPassword As String, ByVal strPath As String)
If Left(strPath, 1) = "/" Or Left(strPath, 1) = "\" Then
strPath = strPath.Remove(1, 1)
End If
If Right(strPath, 1) = "/" Or Right(strPath, 1) = "\" Then
strPath = strPath.Remove(strPath.Length, 1)
End If
Dim objTCPCommand As New TcpClient()
Dim objTCPData As New TcpClient()
Dim objTCPCommandStream As NetworkStream
Dim objTCPDataStream As NetworkStream
'close data connection
ReadData(objTCPCommand, objTCPCommandStream)
objTCPDataStream.Close()
objTCPData.Close()
'quit and close control connection
WriteData(objTCPCommandStream, "QUIT" & vbCrLf)
objTCPCommandStream.Close()
objTCPCommand.Close()
Catch Err As Exception
MsgBox(Err.ToString)
End Try
End Function
Private Function ReadData(ByVal TCPClient, ByVal NETStream) As String
Dim sData As String
Do Until sData <> ""
ReDim bytReading(TCPClient.ReceiveBufferSize)
NETStream.Read(bytReading, 0, TCPClient.ReceiveBufferSize)
sData = Trim(System.Text.Encoding.ASCII.GetString(bytReading))
ReadData = sData
Loop
End Function
Private Sub WriteData(ByVal NETStream As Object, ByVal sData As String)
bytWriting = System.Text.Encoding.ASCII.GetBytes(sData)
NETStream.Write(bytWriting, 0, bytWriting.Length)
End Sub
Private Sub WriteData(ByVal NETStream As Object, ByVal sData As String)
bytWriting = System.Text.Encoding.ASCII.GetBytes(sData)
NETStream.Write(bytWriting, 0, bytWriting.Length)
End Sub