Hallo,
ich bin momentan damit beschäfftigt ein kleines Tool zu schreiben mit dem von einem lokalen Rechner, der hinter einem Proxy sitzt (Ken), Daten von einem FTP herunter- und hochgeladen werden können.
Der download funktioniert auch einwandfrei
Wenn ich jetzt aber einen Upload machen möchte mit folgendem Code erhalte ich Eine Fehlermeldung ("Der angeforderte FTP-Befehl wird nicht unterstützt, wenn ein HTTP-Proxy verwendet wird.")
Da ich schon seit einigen Wochen immer wieder nach Lösungen für dieses Problem suche, bin ich auch schon auf Fragen in diese Richtung gestoßen. Da wird als mögliche Lösung vorgeschlagen uploadRequest.Proxy = Nothing zu setzen. Aber ich nehme an, das hat nur Sinn, wenn man auch keinen Proxy hat.
Aber da ich mich gerne überraschen lasse habe ich es Trotzdem probiert. Das Ergebnis war eine andere Fehlermeldung: "Die Verbindung mit dem Remoteserver kann nicht hergestellt werden"
Nun würde ich mich wirklich freuen, wenn mit jemand von euch bei diesem Problem weiterhelfen könnte. Irgendwie muss das doch gehen!
Gruß,
Athlone
ich bin momentan damit beschäfftigt ein kleines Tool zu schreiben mit dem von einem lokalen Rechner, der hinter einem Proxy sitzt (Ken), Daten von einem FTP herunter- und hochgeladen werden können.
Der download funktioniert auch einwandfrei
Public Sub GetFileFromFTP()
Const BUFFERSIZE = 64 * 1024
Dim strURL As String
Dim strURI As String
Dim strLocalFilePathAndName As String
Dim FTPrequest As FtpWebRequest
Dim FTPresponse As FtpWebResponse
Dim FTPproxy As WebProxy
Dim FileStream As IO.FileStream
Dim BinaryReader As IO.BinaryReader
Dim BinaryWriter As IO.BinaryWriter
Dim bytaBuffer(BUFFERSIZE - 1) As Byte
Dim intBufferLoop As Integer
strURL = fCombinePath(fCombinePath(info.strFTPserver, info.strFTPpath), info.strFTPfile)
strURI = fGenerateURI()
strLocalFilePathAndName = fCombinePath(info.strLocalPath, info.strLocalFile)
FTPproxy = New WebProxy(info.strProxy, info.intProxyPort)
FTPrequest = FtpWebRequest.Create("ftp://" & info.strFTPserver.Substring(4) & "/" & info.strFTPfile)
FTPrequest.Proxy = FTPproxy
FTPrequest.Credentials = New NetworkCredential(info.strFTPuser, info.strFTPpassword)
FTPresponse = FTPrequest.GetResponse()
FileStream = New IO.FileStream(strLocalFilePathAndName, IO.FileMode.Create)
BinaryReader = New IO.BinaryReader(FTPresponse.GetResponseStream)
BinaryWriter = New IO.BinaryWriter(FileStream)
Do
intBufferLoop = BinaryReader.Read(bytaBuffer, 0, BUFFERSIZE)
BinaryWriter.Write(bytaBuffer, 0, intBufferLoop)
Dim nfoFile As New FileInfo(strLocalFilePathAndName)
Form1.StatusStrip1.Items(0).Text = CType(nfoFile.Length / 1024 / 1024, Integer) & " MByte heruntergeladen"
Threading.Thread.Sleep(5)
Form1.StatusStrip1.Update()
Loop Until intBufferLoop = 0
BinaryReader.Close()
BinaryWriter.Close()
FileStream.Close()
End Sub
Const BUFFERSIZE = 64 * 1024
Dim strURL As String
Dim strURI As String
Dim strLocalFilePathAndName As String
Dim FTPrequest As FtpWebRequest
Dim FTPresponse As FtpWebResponse
Dim FTPproxy As WebProxy
Dim FileStream As IO.FileStream
Dim BinaryReader As IO.BinaryReader
Dim BinaryWriter As IO.BinaryWriter
Dim bytaBuffer(BUFFERSIZE - 1) As Byte
Dim intBufferLoop As Integer
strURL = fCombinePath(fCombinePath(info.strFTPserver, info.strFTPpath), info.strFTPfile)
strURI = fGenerateURI()
strLocalFilePathAndName = fCombinePath(info.strLocalPath, info.strLocalFile)
FTPproxy = New WebProxy(info.strProxy, info.intProxyPort)
FTPrequest = FtpWebRequest.Create("ftp://" & info.strFTPserver.Substring(4) & "/" & info.strFTPfile)
FTPrequest.Proxy = FTPproxy
FTPrequest.Credentials = New NetworkCredential(info.strFTPuser, info.strFTPpassword)
FTPresponse = FTPrequest.GetResponse()
FileStream = New IO.FileStream(strLocalFilePathAndName, IO.FileMode.Create)
BinaryReader = New IO.BinaryReader(FTPresponse.GetResponseStream)
BinaryWriter = New IO.BinaryWriter(FileStream)
Do
intBufferLoop = BinaryReader.Read(bytaBuffer, 0, BUFFERSIZE)
BinaryWriter.Write(bytaBuffer, 0, intBufferLoop)
Dim nfoFile As New FileInfo(strLocalFilePathAndName)
Form1.StatusStrip1.Items(0).Text = CType(nfoFile.Length / 1024 / 1024, Integer) & " MByte heruntergeladen"
Threading.Thread.Sleep(5)
Form1.StatusStrip1.Update()
Loop Until intBufferLoop = 0
BinaryReader.Close()
BinaryWriter.Close()
FileStream.Close()
End Sub
Wenn ich jetzt aber einen Upload machen möchte mit folgendem Code erhalte ich Eine Fehlermeldung ("Der angeforderte FTP-Befehl wird nicht unterstützt, wenn ein HTTP-Proxy verwendet wird.")
Public Sub Upload()
Dim requestStream As IO.Stream = Nothing
Dim fileStream As IO.FileStream = Nothing
Dim uploadResponse As FtpWebResponse = Nothing
Dim FTPproxy As WebProxy
Try
FTPproxy = New WebProxy(info.strProxy, info.intProxyPort)
Dim uploadRequest As WebRequest = WebRequest.Create("ftp://" & info.strFTPserver.Substring(4) & "/" & info.strFTPfile)
uploadRequest.Method = WebRequestMethods.Ftp.UploadFile
uploadRequest.Credentials = New NetworkCredential(info.strFTPuser, info.strFTPpassword)
uploadRequest.Proxy = FTPproxy
requestStream = uploadRequest.GetRequestStream()
fileStream = IO.File.Open(fCombinePath(info.strLocalPath, info.strLocalFile), IO.FileMode.Open)
Dim buffer(1024) As Byte
Dim bytesRead As Integer
While True
bytesRead = fileStream.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then
Exit While
End If
requestStream.Write(buffer, 0, bytesRead)
End While
requestStream.Close()
uploadResponse = uploadRequest.GetResponse()
Form1.StatusStrip1.Items(0).Text = "Upload complete."
Catch ex As UriFormatException
MsgBox(ex.Message)
Catch ex As IO.IOException
MsgBox(ex.Message)
Catch ex As WebException
MsgBox(ex.Message)
Finally
If uploadResponse IsNot Nothing Then
uploadResponse.Close()
End If
If fileStream IsNot Nothing Then
fileStream.Close()
End If
If requestStream IsNot Nothing Then
requestStream.Close()
End If
End Try
End Sub
Dim requestStream As IO.Stream = Nothing
Dim fileStream As IO.FileStream = Nothing
Dim uploadResponse As FtpWebResponse = Nothing
Dim FTPproxy As WebProxy
Try
FTPproxy = New WebProxy(info.strProxy, info.intProxyPort)
Dim uploadRequest As WebRequest = WebRequest.Create("ftp://" & info.strFTPserver.Substring(4) & "/" & info.strFTPfile)
uploadRequest.Method = WebRequestMethods.Ftp.UploadFile
uploadRequest.Credentials = New NetworkCredential(info.strFTPuser, info.strFTPpassword)
uploadRequest.Proxy = FTPproxy
requestStream = uploadRequest.GetRequestStream()
fileStream = IO.File.Open(fCombinePath(info.strLocalPath, info.strLocalFile), IO.FileMode.Open)
Dim buffer(1024) As Byte
Dim bytesRead As Integer
While True
bytesRead = fileStream.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then
Exit While
End If
requestStream.Write(buffer, 0, bytesRead)
End While
requestStream.Close()
uploadResponse = uploadRequest.GetResponse()
Form1.StatusStrip1.Items(0).Text = "Upload complete."
Catch ex As UriFormatException
MsgBox(ex.Message)
Catch ex As IO.IOException
MsgBox(ex.Message)
Catch ex As WebException
MsgBox(ex.Message)
Finally
If uploadResponse IsNot Nothing Then
uploadResponse.Close()
End If
If fileStream IsNot Nothing Then
fileStream.Close()
End If
If requestStream IsNot Nothing Then
requestStream.Close()
End If
End Try
End Sub
Da ich schon seit einigen Wochen immer wieder nach Lösungen für dieses Problem suche, bin ich auch schon auf Fragen in diese Richtung gestoßen. Da wird als mögliche Lösung vorgeschlagen uploadRequest.Proxy = Nothing zu setzen. Aber ich nehme an, das hat nur Sinn, wenn man auch keinen Proxy hat.
Aber da ich mich gerne überraschen lasse habe ich es Trotzdem probiert. Das Ergebnis war eine andere Fehlermeldung: "Die Verbindung mit dem Remoteserver kann nicht hergestellt werden"
Nun würde ich mich wirklich freuen, wenn mit jemand von euch bei diesem Problem weiterhelfen könnte. Irgendwie muss das doch gehen!
Gruß,
Athlone
Comment