| |
Fortgeschrittene ProgrammierungFTP Programm | | | Autor: Patte | Datum: 29.07.14 21:03 |
| ICh habe ein kleines Problem und finde den Fehler nicht ich habe ein kleines FTP Programm geschrieben
nichts besonderes ... jetzt wenn ich auf download oder upload klicke bekomme ich den Fehler :
Der angeforderte Uri ist für diesen FTP-Befehl ungültig
Ich weiß nur grade nicht was ich falsch gemacht habe ^^
ich kopiere mal den download teil hier rein
wenn mich jemand mal mit der nase draufhauen kann was ich verbockt habe , wäre ich sehr dankbar
(URL = ftp://xxx.de) (bk= benutzerkonto) (PW= is klar oder ^^)
Private Sub downloadftp(ByVal URL As String, ByVal bk As String, ByVal pw As _
String)
Dim requ As FtpWebRequest = Nothing
Dim resp As FtpWebResponse = Nothing
Dim respStrm As Stream = Nothing
Dim fileStrm As FileStream = Nothing
Try
requ = CType(WebRequest.Create(URL), FtpWebRequest)
requ.Credentials = New NetworkCredential(bk, pw)
requ.Method = WebRequestMethods.Ftp.DownloadFile
resp = CType(requ.GetResponse(), FtpWebResponse)
respStrm = resp.GetResponseStream()
SaveFileDialog1.FileName = Path.GetFileName( _
requ.RequestUri.LocalPath)
If (SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) _
Then
fileStrm = File.Create(SaveFileDialog1.FileName)
Dim buff(1024) As Byte
Dim bytesRead As Integer = 0
While (True)
bytesRead = respStrm.Read(buff, 0, buff.Length)
If (bytesRead = 0) Then Exit While
fileStrm.Write(buff, 0, bytesRead)
End While
ToolStripStatusLabel1.Text = "Download komplett"
End If
Catch ex As UriFormatException
ToolStripStatusLabel1.Text = ex.Message
Catch ex As WebException
ToolStripStatusLabel2.Text = ex.Message
Catch ex As IOException
ToolStripStatusLabel2.Text = ex.Message
Finally
If respStrm IsNot Nothing Then respStrm.Close()
If fileStrm IsNot Nothing Then fileStrm.Close()
End Try
End Sub
Beitrag wurde zuletzt am 29.07.14 um 21:09:03 editiert. | |
Re: FTP Programm | | | Autor: Kuno60 | Datum: 05.08.14 22:32 |
| Hallo,
der Beitrag ist im falschen Forum.
Der Download-Teil ist korrekt geschrieben. Da wird wohl der Fehler in der URL liegen.
Für einfache Zwecke reicht auch "My.Computer.Network.DownloadFile" und hat auch eine optionale Fortschrittsanzeige. | |
Re: FTP Programm | | | Autor: Patte | Datum: 06.08.14 06:44 |
| sry das es im falschem Forum gelandet ist ...
ich kopiere hier mal alles
also ganz kurz
das programm holt sich die ip des ftp servers (meine externe Festplatte mit dieser funktion) vom webspace aus einer txt Datei (IP)
Der Inhalt des Servers wird mir in einer Listbox angezeigt --klappt
wenn ich jetzt (zum test habe ich eine einfache txt datei genommen ) diese anklicke kopiert er den link in Textbox1 -- klappt übern browser nach passwort eingabe kann man diese datei runterladen
nur upload und Download habe ich den fehler drinne (der angeforderte URI ist für diesen FTP-Befehl ungültig)
| |
Re: FTP Programm | | | Autor: Patte | Datum: 06.08.14 06:45 |
| Imports System.IO
Imports System.Net
Public Class Form9
Private Sub listftp(ByVal URL As String, ByVal bk As String, ByVal pw As _
String)
Dim requ As FtpWebRequest = Nothing
Dim resp As FtpWebResponse = Nothing
Dim reader As StreamReader = Nothing
Try
requ = CType(FtpWebRequest.Create(URL), FtpWebRequest)
requ.Credentials = New NetworkCredential("bk", "pw")
requ.Method = WebRequestMethods.Ftp.ListDirectory
resp = CType(requ.GetResponse(), FtpWebResponse)
reader = New StreamReader(resp.GetResponseStream())
While (reader.Peek() > -1)
ListBox1.Items.Add(reader.ReadLine())
End While
ToolStripStatusLabel1.Text = "Auflistung komplett"
Catch ex As UriFormatException
ToolStripStatusLabel1.Text = ex.Message
Catch ex As WebException
ToolStripStatusLabel2.Text = ex.Message
Finally
If reader IsNot Nothing Then reader.Close()
End Try
End Sub
Private Sub downloadftp(ByVal URL As String, ByVal bk As String, ByVal pw _
As String)
Dim wcl As New Net.WebClient
Dim ip As String
ip = wcl.DownloadString("mein webspace für die ip ")
Dim requ As FtpWebRequest = Nothing
Dim resp As FtpWebResponse = Nothing
Dim respStrm As Stream = Nothing
Dim fileStrm As FileStream = Nothing
Try
requ = CType(WebRequest.Create(URL), FtpWebRequest)
requ.Credentials = New NetworkCredential("bk", "pw")
requ.Method = WebRequestMethods.Ftp.DownloadFile
resp = CType(requ.GetResponse(), FtpWebResponse)
respStrm = resp.GetResponseStream()
SaveFileDialog1.FileName = Path.GetFileName( _
requ.RequestUri.LocalPath)
If (SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) _
Then
fileStrm = File.Create(SaveFileDialog1.FileName)
Dim buff(1024) As Byte
Dim bytesRead As Integer = 0
While (True)
bytesRead = respStrm.Read(buff, 0, buff.Length)
If (bytesRead = 0) Then Exit While
fileStrm.Write(buff, 0, bytesRead)
End While
ToolStripStatusLabel1.Text = "Download komplett"
End If
Catch ex As UriFormatException
ToolStripStatusLabel1.Text = ex.Message
Catch ex As WebException
ToolStripStatusLabel2.Text = ex.Message
Catch ex As IOException
ToolStripStatusLabel2.Text = ex.Message
Finally
If respStrm IsNot Nothing Then respStrm.Close()
If fileStrm IsNot Nothing Then fileStrm.Close()
End Try
End Sub | |
Re: FTP Programm | | | Autor: Patte | Datum: 06.08.14 06:46 |
| 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 | |
| Sie sind nicht angemeldet! Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
|
|
Neu! sevCoolbar 3.0
Professionelle Toolbars im modernen Design!
Mit sevCoolbar erstellen Sie in wenigen Minuten ansprechende und moderne Toolbars und passen diese optimal an das Layout Ihrer Anwendung an (inkl. große Symbolbibliothek) - für VB und MS-Access Weitere InfosTipp des Monats TOP Entwickler-Paket
TOP-Preis!!
Mit der Developer CD erhalten Sie insgesamt 24 Entwickler- komponenten und Windows-DLLs. Die Einzelkomponenten haben einen Gesamtwert von 1605.50 EUR...
Jetzt nur 599,00 EURWeitere Infos
|