Imports System.Net
Imports System.IO
Imports System.Net.Sockets
Imports System.Text
Imports System.Windows.Forms
public class FtpClientVB
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class ftpCreate
Private ftpTcpClient As TcpClient
Public ResponseStream As NetworkStream
Public ReturnNameMessage As String
Public ReturnPwdMessage As String
Public Sub ftpLogin(ByVal strName As String, ByVal strPWD As String, ByVal strftpLogin As String)
Try
Dim strCommand As String
Dim strReturnMessage As String
Dim bteSendBytes() As Byte
Dim bteRetruenBytes() As Byte
Dim intReturnByteLength As Integer
Dim ftpTcpClient As TcpClient = New TcpClient(strftpLogin, 21)
ResponseStream = ftpTcpClient.GetStream
strCommand = "USER " + strName + vbCrLf
bteSendBytes = Encoding.ASCII.GetBytes(strCommand)
ResponseStream.Write(bteSendBytes, 0, bteSendBytes.Length)
intReturnByteLength = ftpTcpClient.ReceiveBufferSize
ReDim bteRetruenBytes(intReturnByteLength)
ResponseStream.Read(bteRetruenBytes, 0, intReturnByteLength)
strReturnMessage = Encoding.ASCII.GetString(bteRetruenBytes) + "/ "
ReturnNameMessage = strCommand + strReturnMessage
strCommand = "PASS " + strPWD + vbCrLf
Array.Clear(bteSendBytes, 0, bteSendBytes.Length)
bteSendBytes = Encoding.ASCII.GetBytes(strCommand)
ResponseStream.Write(bteSendBytes, 0, bteSendBytes.Length)
intReturnByteLength = ftpTcpClient.ReceiveBufferSize
ReDim bteRetruenBytes(intReturnByteLength)
ResponseStream.Read(bteRetruenBytes, 0, intReturnByteLength)
strReturnMessage = Encoding.ASCII.GetString(bteRetruenBytes) + "/ "
ReturnPwdMessage = strCommand + strReturnMessage + vbCrLf
Catch ex As SocketException
ReturnPwdMessage = ex.Message
End Try
End Sub
End Class
Public Class ftpClient
Dim ReturnNameMessage
Dim ReturnPwdMessage
Dim myftpCreate As ftpCreate
Public Sub LogInFTP(ByVal strName As String, ByVal strPWD As String, ByVal strftpLogin As String)
myftpCreate = New ftpCreate()
myftpCreate.ftpLogin(strName, strPWD, strftpLogin)
ReturnNameMessage = myftpCreate.ReturnNameMessage
ReturnPwdMessage = myftpCreate.ReturnPwdMessage
End Sub
Public ReadOnly Property GetReturnNameMessage() As String
Get
Return ReturnNameMessage
End Get
End Property
Public ReadOnly Property GetReturnPwdMessage() As String
Get
Return ReturnPwdMessage
End Get
End Property
Public Sub FTPUpLoad(ByVal strFilePath As String, ByVal strFtpPath As String, ByRef pstrReturnMessage As String)
Dim UPFile As New FileStream(strFilePath, FileMode.Open)
Dim bytUPFile() As Byte
Dim lngFileLength As Long
Dim ftpStream As NetworkStream = myftpCreate.ResponseStream
Dim returnMessage As String
Dim UpLoadStream As NetworkStream
Try
lngFileLength = UPFile.Length
ReDim bytUPFile(lngFileLength)
UPFile.Read(bytUPFile, 0, lngFileLength)
FTPCommands(ftpStream, "PASV", returnMessage)
UpLoadStream = GetConnectTcpClient(returnMessage)
FTPCommands(ftpStream, "TYPE I", returnMessage)
FTPCommands(ftpStream, "STOR " + strFtpPath, returnMessage)
pstrReturnMessage += returnMessage.TrimEnd
UpLoadStream.Write(bytUPFile, 0, lngFileLength)
UpLoadStream.Close()
UPFile.Close()
Catch ex As Exception
pstrReturnMessage = ex.Message
End Try
End Sub
Public Sub FTPDownLoad(ByVal strFilePath As String, ByVal strFtpPath As String, ByRef pstrReturnMessage As String)
Dim UPFile As New FileStream(strFtpPath, FileMode.Create)
Dim bytUPFile() As Byte
Dim lngFileLength As Long
Dim ftpStream As NetworkStream = myftpCreate.ResponseStream
Dim returnMessage As String
FTPCommands(ftpStream, "PASV", returnMessage)
Dim DownloadStream As NetworkStream
DownloadStream = GetConnectTcpClient(returnMessage)
FTPCommands(ftpStream, "TYPE I", returnMessage)
FTPCommands(ftpStream, "RETR " + strFilePath, returnMessage)
pstrReturnMessage += returnMessage
ReDim bytUPFile(1024)
Do
lngFileLength = DownloadStream.Read(bytUPFile, 0, 1024)
UPFile.Write(bytUPFile, 0, lngFileLength)
Loop While lngFileLength > 0
UPFile.Close()
DownloadStream.Close()
End Sub
Private Function FTPCommands(ByVal ftpStream As NetworkStream, ByVal strCommand As String, ByRef strMessage As String) As Integer
Dim bteCommand() As Byte
bteCommand = Encoding.ASCII.GetBytes(strCommand + vbCrLf)
ftpStream.Write(bteCommand, 0, bteCommand.Length)
Dim b(360000) As Byte
ftpStream.Read(b, 0, 360000)
strMessage = Encoding.ASCII.GetString(b)
End Function
Private Function GetConnectTcpClient(ByVal respMessage As String) As NetworkStream
Dim i As Integer
Dim strIP As String
Dim strIPs() As String
Dim strAddress As String
Dim intPort As Integer
Try
strIP = respMessage.Substring(respMessage.IndexOf("(")).Replace("(", "")
strIPs = strIP.Split(",")
strIP = ""
For i = 0 To 3
strIP += strIPs(i) + "."
Next
strAddress = strIP.Substring(0, strIP.Length - 1)
intPort = Integer.Parse(strIPs(4)) * 256 + _
Integer.Parse(strIPs(5).Substring(0, strIPs(5).IndexOf(")")))
Dim dataClient As New TcpClient()
Dim cIPEP As New IPEndPoint(IPAddress.Parse(strAddress), intPort)
dataClient.Connect(cIPEP)
Return dataClient.GetStream
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Function
Public Function CreateDir(ByVal strDirPath As String) As String
Dim ftpStream As NetworkStream = myftpCreate.ResponseStream
Dim returnMessage As String
FTPCommands(ftpStream, "MKD " + strDirPath, returnMessage)
returnMessage = "Creating Dir" + vbCrLf + returnMessage
Return returnMessage
ftpStream.Close()
End Function
Public Function DeleteDir(ByVal strDirPath As String) As String
Dim ftpStream As NetworkStream = myftpCreate.ResponseStream
Dim returnMessage As String
FTPCommands(ftpStream, "RMD " + strDirPath, returnMessage)
returnMessage = "Delete Dir" + vbCrLf + returnMessage
Return returnMessage
ftpStream.Close()
End Function
Public Function PrintDir() As String
Dim ftpStream As NetworkStream = myftpCreate.ResponseStream
Dim returnMessage As String
FTPCommands(ftpStream, "PWD ", returnMessage)
returnMessage = returnMessage
Return returnMessage
ftpStream.Close()
End Function
Public Function ChangeDir(ByVal strDirPath As String) As String
Dim ftpStream As NetworkStream = myftpCreate.ResponseStream
Dim returnMessage As String
FTPCommands(ftpStream, "CWD " + strDirPath, returnMessage)
returnMessage = returnMessage
Return returnMessage
ftpStream.Close()
End Function
Public Function DeleteFile(ByVal strFile As String) As String
Dim ftpStream As NetworkStream = myftpCreate.ResponseStream
Dim returnMessage As String
FTPCommands(ftpStream, "DELE " + strFile, returnMessage)
returnMessage = returnMessage
Return returnMessage
ftpStream.Close()
End Function
Public Function QuitFTP(ByVal strFile As String) As String
Dim ftpStream As NetworkStream = myftpCreate.ResponseStream
Dim returnMessage As String
FTPCommands(ftpStream, "QUIT", returnMessage)
returnMessage = returnMessage
Return returnMessage
ftpStream.Close()
End Function
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
Friend WithEvents loginPage As System.Windows.Forms.TabPage
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtPassword As System.Windows.Forms.TextBox
Friend WithEvents txtName As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents ftpLoign As System.Windows.Forms.TextBox
Friend WithEvents btnLogin As System.Windows.Forms.Button
Friend WithEvents DownloadPage As System.Windows.Forms.TabPage
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents txtMessage As System.Windows.Forms.TextBox
Friend WithEvents btnFTPUpLoad As System.Windows.Forms.Button
Friend WithEvents UploadPage As System.Windows.Forms.TabPage
Friend WithEvents txtFilePath As System.Windows.Forms.TextBox
Friend WithEvents btnFTPDownLoad As System.Windows.Forms.Button
Friend WithEvents txtFTPDownLoadPath As System.Windows.Forms.TextBox
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents doFilePath As System.Windows.Forms.TextBox
Friend WithEvents txtDestFile As System.Windows.Forms.TextBox
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents btnDelete As System.Windows.Forms.Button
Friend WithEvents Dir As System.Windows.Forms.TabPage
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents txtDir As System.Windows.Forms.TextBox
Friend WithEvents btnChange As System.Windows.Forms.Button
Friend WithEvents btnQuit As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TabControl1 = New System.Windows.Forms.TabControl()
Me.loginPage = New System.Windows.Forms.TabPage()
Me.btnQuit = New System.Windows.Forms.Button()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.txtPassword = New System.Windows.Forms.TextBox()
Me.txtName = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.ftpLoign = New System.Windows.Forms.TextBox()
Me.btnLogin = New System.Windows.Forms.Button()
Me.UploadPage = New System.Windows.Forms.TabPage()
Me.Label9 = New System.Windows.Forms.Label()
Me.Label5 = New System.Windows.Forms.Label()
Me.txtDestFile = New System.Windows.Forms.TextBox()
Me.txtFilePath = New System.Windows.Forms.TextBox()
Me.btnFTPUpLoad = New System.Windows.Forms.Button()
Me.DownloadPage = New System.Windows.Forms.TabPage()
Me.btnDelete = New System.Windows.Forms.Button()
Me.Label8 = New System.Windows.Forms.Label()
Me.doFilePath = New System.Windows.Forms.TextBox()
Me.Label7 = New System.Windows.Forms.Label()
Me.txtFTPDownLoadPath = New System.Windows.Forms.TextBox()
Me.btnFTPDownLoad = New System.Windows.Forms.Button()
Me.Dir = New System.Windows.Forms.TabPage()
Me.btnChange = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Label6 = New System.Windows.Forms.Label()
Me.txtDir = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.Label4 = New System.Windows.Forms.Label()
Me.txtMessage = New System.Windows.Forms.TextBox()
Me.TabControl1.SuspendLayout()
Me.loginPage.SuspendLayout()
Me.UploadPage.SuspendLayout()
Me.DownloadPage.SuspendLayout()
Me.Dir.SuspendLayout()
Me.SuspendLayout()
'
'TabControl1
'
Me.TabControl1.Controls.AddRange(New System.Windows.Forms.Control() {Me.loginPage, Me.DownloadPage, Me.UploadPage, Me.Dir})
Me.TabControl1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
Me.TabControl1.Location = New System.Drawing.Point(31, 6)
Me.TabControl1.Name = "TabControl1"
Me.TabControl1.SelectedIndex = 0
Me.TabControl1.Size = New System.Drawing.Size(655, 122)
Me.TabControl1.TabIndex = 12
'
'loginPage
'
Me.loginPage.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnQuit, Me.Label3, Me.Label2, Me.txtPassword, Me.txtName, Me.Label1, Me.ftpLoign, Me.btnLogin})
Me.loginPage.Location = New System.Drawing.Point(4, 25)
Me.loginPage.Name = "loginPage"
Me.loginPage.Size = New System.Drawing.Size(647, 93)
Me.loginPage.TabIndex = 0
Me.loginPage.Text = "Login"
'
'btnQuit
'
Me.btnQuit.Location = New System.Drawing.Point(461, 8)
Me.btnQuit.Name = "btnQuit"
Me.btnQuit.Size = New System.Drawing.Size(112, 24)
Me.btnQuit.TabIndex = 14
Me.btnQuit.Tag = "3"
Me.btnQuit.Text = "Quit"
'
'Label3
'
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
Me.Label3.Location = New System.Drawing.Point(20, 40)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(93, 16)
Me.Label3.TabIndex = 13
Me.Label3.Text = "Password"
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
Me.Label2.Location = New System.Drawing.Point(20, 16)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(93, 16)
Me.Label2.TabIndex = 12
Me.Label2.Text = "Account"
'
'txtPassword
'
Me.txtPassword.Location = New System.Drawing.Point(123, 32)
Me.txtPassword.Name = "txtPassword"
Me.txtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtPassword.Size = New System.Drawing.Size(205, 22)
Me.txtPassword.TabIndex = 11
Me.txtPassword.Tag = "1"
Me.txtPassword.Text = "1"
'
'txtName
'
Me.txtName.Location = New System.Drawing.Point(123, 8)
Me.txtName.Name = "txtName"
Me.txtName.Size = New System.Drawing.Size(205, 22)
Me.txtName.TabIndex = 10
Me.txtName.Tag = "0"
Me.txtName.Text = "Administrator"
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
Me.Label1.Location = New System.Drawing.Point(10, 64)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(92, 16)
Me.Label1.TabIndex = 9
Me.Label1.Text = "FTP Server"
'
'ftpLoign
'
Me.ftpLoign.Location = New System.Drawing.Point(123, 64)
Me.ftpLoign.Name = "ftpLoign"
Me.ftpLoign.Size = New System.Drawing.Size(502, 22)
Me.ftpLoign.TabIndex = 8
Me.ftpLoign.Tag = "2"
Me.ftpLoign.Text = "192.168.1.100"
'
'btnLogin
'
Me.btnLogin.Location = New System.Drawing.Point(338, 8)
Me.btnLogin.Name = "btnLogin"
Me.btnLogin.Size = New System.Drawing.Size(113, 24)
Me.btnLogin.TabIndex = 7
Me.btnLogin.Tag = "3"
Me.btnLogin.Text = "Login FTP"
'
'UploadPage
'
Me.UploadPage.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label9, Me.Label5, Me.txtDestFile, Me.txtFilePath, Me.btnFTPUpLoad})
Me.UploadPage.Location = New System.Drawing.Point(4, 25)
Me.UploadPage.Name = "UploadPage"
Me.UploadPage.Size = New System.Drawing.Size(647, 93)
Me.UploadPage.TabIndex = 1
Me.UploadPage.Text = "Upload"
Me.UploadPage.Visible = False
'
'Label9
'
Me.Label9.Location = New System.Drawing.Point(13, 62)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(82, 16)
Me.Label9.TabIndex = 9
Me.Label9.Text = "FTP File"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(10, 29)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(82, 16)
Me.Label5.TabIndex = 4
Me.Label5.Text = "Upload"
'
'txtDestFile
'
Me.txtDestFile.Location = New System.Drawing.Point(102, 56)
Me.txtDestFile.Name = "txtDestFile"
Me.txtDestFile.Size = New System.Drawing.Size(400, 22)
Me.txtDestFile.TabIndex = 3
Me.txtDestFile.Text = "yourfile.txt"
'
'txtFilePath
'
Me.txtFilePath.Location = New System.Drawing.Point(102, 24)
Me.txtFilePath.Name = "txtFilePath"
Me.txtFilePath.Size = New System.Drawing.Size(400, 22)
Me.txtFilePath.TabIndex = 1
Me.txtFilePath.Text = "c:\yourfile.txt"
'
'btnFTPUpLoad
'
Me.btnFTPUpLoad.Location = New System.Drawing.Point(513, 24)
Me.btnFTPUpLoad.Name = "btnFTPUpLoad"
Me.btnFTPUpLoad.Size = New System.Drawing.Size(113, 24)
Me.btnFTPUpLoad.TabIndex = 0
Me.btnFTPUpLoad.Text = "Upload"
'
'DownloadPage
'
Me.DownloadPage.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnDelete, Me.Label8, Me.doFilePath, Me.Label7, Me.txtFTPDownLoadPath, Me.btnFTPDownLoad})
Me.DownloadPage.Location = New System.Drawing.Point(4, 25)
Me.DownloadPage.Name = "DownloadPage"
Me.DownloadPage.Size = New System.Drawing.Size(647, 93)
Me.DownloadPage.TabIndex = 2
Me.DownloadPage.Text = "Download"
Me.DownloadPage.Visible = False
'
'btnDelete
'
Me.btnDelete.Location = New System.Drawing.Point(512, 56)
Me.btnDelete.Name = "btnDelete"
Me.btnDelete.Size = New System.Drawing.Size(113, 24)
Me.btnDelete.TabIndex = 9
Me.btnDelete.Text = "Delete file"
'
'Label8
'
Me.Label8.Location = New System.Drawing.Point(10, 30)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(82, 16)
Me.Label8.TabIndex = 8
Me.Label8.Text = "FTP File"
'
'doFilePath
'
Me.doFilePath.Location = New System.Drawing.Point(92, 56)
Me.doFilePath.Name = "doFilePath"
Me.doFilePath.Size = New System.Drawing.Size(410, 22)
Me.doFilePath.TabIndex = 7
Me.doFilePath.Text = "c:\yourfile.txt"
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(10, 61)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(82, 16)
Me.Label7.TabIndex = 6
Me.Label7.Text = "Target File"
'
'txtFTPDownLoadPath
'
Me.txtFTPDownLoadPath.Location = New System.Drawing.Point(92, 24)
Me.txtFTPDownLoadPath.Name = "txtFTPDownLoadPath"
Me.txtFTPDownLoadPath.Size = New System.Drawing.Size(410, 22)
Me.txtFTPDownLoadPath.TabIndex = 4
Me.txtFTPDownLoadPath.Text = "yourfile.txt"
'
'btnFTPDownLoad
'
Me.btnFTPDownLoad.Location = New System.Drawing.Point(513, 24)
Me.btnFTPDownLoad.Name = "btnFTPDownLoad"
Me.btnFTPDownLoad.Size = New System.Drawing.Size(113, 24)
Me.btnFTPDownLoad.TabIndex = 3
Me.btnFTPDownLoad.Text = "Download file"
'
'Dir
'
Me.Dir.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnChange, Me.Button3, Me.Button2, Me.Label6, Me.txtDir, Me.Button1})
Me.Dir.Location = New System.Drawing.Point(4, 25)
Me.Dir.Name = "Dir"
Me.Dir.Size = New System.Drawing.Size(647, 93)
Me.Dir.TabIndex = 3
Me.Dir.Text = "Dir"
'
'btnChange
'
Me.btnChange.Location = New System.Drawing.Point(522, 16)
Me.btnChange.Name = "btnChange"
Me.btnChange.Size = New System.Drawing.Size(113, 22)
Me.btnChange.TabIndex = 10
Me.btnChange.Text = "Change Dir"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(399, 56)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(113, 22)
Me.Button3.TabIndex = 9
Me.Button3.Text = "Current Folder"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(276, 56)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(113, 22)
Me.Button2.TabIndex = 8
Me.Button2.Text = "Delete"
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(20, 20)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(82, 16)
Me.Label6.TabIndex = 7
Me.Label6.Text = "FTP Dir"
'
'txtDir
'
Me.txtDir.Location = New System.Drawing.Point(113, 16)
Me.txtDir.Name = "txtDir"
Me.txtDir.Size = New System.Drawing.Size(399, 22)
Me.txtDir.TabIndex = 6
Me.txtDir.Text = "C"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(154, 56)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(112, 22)
Me.Button1.TabIndex = 5
Me.Button1.Text = "New"
'
'Label4
'
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
Me.Label4.Location = New System.Drawing.Point(31, 136)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(70, 16)
Me.Label4.TabIndex = 11
Me.Label4.Text = "Message"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'txtMessage
'
Me.txtMessage.Location = New System.Drawing.Point(31, 160)
Me.txtMessage.MaxLength = 1048576
Me.txtMessage.Multiline = True
Me.txtMessage.Name = "txtMessage"
Me.txtMessage.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtMessage.Size = New System.Drawing.Size(650, 192)
Me.txtMessage.TabIndex = 10
Me.txtMessage.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(716, 365)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TabControl1, Me.Label4, Me.txtMessage})
Me.TabControl1.ResumeLayout(False)
Me.loginPage.ResumeLayout(False)
Me.UploadPage.ResumeLayout(False)
Me.DownloadPage.ResumeLayout(False)
Me.Dir.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
Dim myftp As New ftpClient()
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim strReturnFields As String = ""
Dim strName As String
Dim strPWD As String
Dim strftpLogin As String
FieldsChek(strReturnFields)
If strReturnFields.Length > 0 Then
MessageBox.Show(strReturnFields + " cannot be empty")
Return
End If
''
strName = txtName.Text
strPWD = txtPassword.Text
strftpLogin = ftpLoign.Text
myftp.LogInFTP(strName, strPWD, strftpLogin)
txtMessage.Text = myftp.GetReturnNameMessage
txtMessage.Text = txtMessage.Text + myftp.GetReturnPwdMessage
End Sub
Private Sub FieldsChek(ByRef strReturnFields As String)
If txtName.Text.Length = 0 Then txtName.Focus()
If txtPassword.Text.Length = 0 Then txtPassword.Focus()
If ftpLoign.Text.Length = 0 Then ftpLoign.Focus()
End Sub
Private Sub btnFTPUpLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFTPUpLoad.Click
Dim strUPFilePath As String
Dim strFtpAddress As String
Dim strMessage As String
strUPFilePath = txtFilePath.Text
strFtpAddress = txtDestFile.Text
myftp.FTPUpLoad(strUPFilePath, strFtpAddress, strMessage)
txtMessage.Text += vbCrLf + strMessage
End Sub
Private Sub btnFTPDownLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFTPDownLoad.Click
Dim strFTPDownLoadPath As String
Dim strFtpAddress As String
Dim strMessage As String
strFTPDownLoadPath = txtFTPDownLoadPath.Text
strFtpAddress = doFilePath.Text
myftp.FTPDownLoad(strFTPDownLoadPath, strFtpAddress, strMessage)
txtMessage.Text += vbCrLf + strMessage
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strDir As String = txtDir.Text
Dim strReturnMessage As String
strReturnMessage = myftp.CreateDir(strDir)
txtMessage.Text += vbCrLf + strReturnMessage
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strDir As String = txtDir.Text
Dim strReturnMessage As String
strReturnMessage = myftp.DeleteDir(strDir)
txtMessage.Text += vbCrLf + strReturnMessage
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim strDir As String = txtDir.Text
Dim strReturnMessage As String
strReturnMessage = myftp.PrintDir()
txtMessage.Text += vbCrLf + strReturnMessage
End Sub
Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
Dim strDir As String = txtDir.Text
Dim strReturnMessage As String
strReturnMessage = myftp.ChangeDir(strDir)
txtMessage.Text += vbCrLf + strReturnMessage
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim strFile As String = txtFTPDownLoadPath.Text
Dim strReturnMessage As String
strReturnMessage = myftp.DeleteFile(strFile)
txtMessage.Text += vbCrLf + strReturnMessage
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Dim strReturnMessage As String
strReturnMessage = myftp.QuitFTP(strReturnMessage)
txtMessage.Text += vbCrLf + strReturnMessage
End Sub
End Class
22.17.FTP Client |
| 22.17.1. | Ftp Client in VB.net | |