Imports System.IO
Public Class Form1
Dim strResults As String = ""
Dim intResult As Integer
Dim strIP As String = "123.123.123.123"
Dim strOutBox = "C:\PROGRA~1\mydir"
Dim strFtpArgs = "C:\PROGRA~1\mydir\FTP.txt"
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim intFileCount As Integer
strResults = ""
TextBox1.Text = ""
'Check to see if there is anything to process
intFileCount = System.IO.Directory.GetFiles(strOutBox).Length()
If intFileCount <= 0 Then
strResults = strResults & "There are no files to process." & vbCrLf
TextBox1.Text = strResults
Exit Sub
Else
Directory.SetCurrentDirectory(strOutBox)
intResult = MsgBox("Are you sure you want to send to outbound files?", MsgBoxStyle.OkCancel)
If intResult <> 1 Then
Exit Sub
End If
End If
Dim CMD As New Threading.Thread(AddressOf GETCMD)
CMD.Start()
End Sub
Private Sub GETCMD()
Dim CMDprocess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
StartInfo.FileName = "cmd"
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
StartInfo.UseShellExecute = False
StartInfo.CreateNoWindow = True
CMDprocess.StartInfo = StartInfo
CMDprocess.Start()
Dim SR As System.IO.StreamReader = CMDprocess.StandardOutput
Dim SW As System.IO.StreamWriter = CMDprocess.StandardInput
SW.WriteLine("ftp -s:" & strFtpArgs & " " & strIP)
SW.WriteLine("exit")
strResults = strResults & SR.ReadToEnd 'returns results of the command window
Me.SetText(strResults)
SW.Close()
SR.Close()
End Sub
Private Sub SetText(ByVal [text] As String)
If Me.TextBox1.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.TextBox1.Text = [text]
End If
End Sub
End Class
|