Private Sub uploadftp(ByVal Url As String, ByVal bk As String, ByVal pw As _
String, ByVal FileName As String)
Dim requ As FtpWebRequest = Nothing
Dim resp As FtpWebResponse = Nothing
Dim requStrm As Stream = Nothing
Dim fileStrm As FileStream = Nothing
Try
Dim wcl As New Net.WebClient
Dim ip As String
ip = wcl.DownloadString("webspace für ip")
requ = CType(WebRequest.Create(Url), FtpWebRequest)
requ.Credentials = New NetworkCredential(bk, pw)
requ.Method = WebRequestMethods.Ftp.UploadFile
requ.Timeout = System.Threading.Timeout.Infinite
requ.Proxy = Nothing
requStrm = requ.GetRequestStream()
Dim buff(2048) As Byte
Dim bytesRead As Integer = 0
fileStrm = File.OpenRead(FileName)
Do While (True)
bytesRead = fileStrm.Read(buff, 0, buff.Length)
If (bytesRead = 0) Then Exit Do
requStrm.Write(buff, 0, bytesRead)
Loop
requStrm.Close()
resp = CType(requ.GetResponse(), FtpWebResponse)
ToolStripStatusLabel1.Text = "Upload Komplett!"
Catch ex As UriFormatException
ToolStripStatusLabel1.Text = ex.Message
Catch ex As IOException
ToolStripStatusLabel2.Text = ex.Message
Catch ex As WebException
ToolStripStatusLabel2.Text = ex.Message
Finally
If resp IsNot Nothing Then resp.Close()
If fileStrm IsNot Nothing Then fileStrm.Close()
If requStrm IsNot Nothing Then requStrm.Close()
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles _
Button1.Click
ListBox1.Items.Clear()
Dim wcl As New Net.WebClient
Dim ip As String
ip = wcl.DownloadString("webspace für ip")
listftp("ftp://" & ip , "bk", "pw")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles _
Button2.Click
Dim wcl As New Net.WebClient
Dim ip As String
ip = wcl.DownloadString("webspace für ip")
downloadftp("ftp://" & ip , "bk", "pw")
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) _
Handles ListBox1.SelectedIndexChanged
Dim wcl As New Net.WebClient
Dim ip As String
ip = wcl.DownloadString("webspace für ip")
TextBox1.Text = "ftp://" & ip &"/"& ListBox1.SelectedItem.ToString
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles _
Button3.Click
If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
Dim wcl As New Net.WebClient
Dim ip As String
ip = wcl.DownloadString("webspace für ip")
uploadftp(OpenFileDialog1.FileName, "ftp://" & ip & "/" + _
Path.GetFileName(OpenFileDialog1.FileName), "bk", "pw")
End If
End Sub
Private Sub Form9_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class |