Hallo,
mit folgenden Code bekomme ich immer die Meldung:
Remoteserver hat einen Fehler zurückgegeben 553
Hier mal der Code:
Public Class Form1
Public Sub UploadFile(ByVal _FileName As String, ByVal _UploadPath As _
String, ByVal _FTPUser As String, ByVal _FTPPass As String)
Dim _FileInfo As New System.IO.FileInfo(_FileName)
' Create FtpWebRequest object from the Uri provided
Dim _FtpWebRequest As System.Net.FtpWebRequest = CType( _
System.Net.FtpWebRequest.Create(New Uri(_UploadPath)), _
System.Net.FtpWebRequest)
' Provide the WebPermission Credintials
_FtpWebRequest.Credentials = New System.Net.NetworkCredential(_FTPUser, _
_FTPPass)
' By default KeepAlive is true, where the control connection is not
' closed
' after a command is executed.
_FtpWebRequest.KeepAlive = False
' set timeout for 20 seconds
_FtpWebRequest.Timeout = 20000
' Specify the command to be executed.
_FtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
' Specify the data transfer type.
_FtpWebRequest.UseBinary = True
' Notify the server about the size of the uploaded file
_FtpWebRequest.ContentLength = _FileInfo.Length
' The buffer size is set to 2kb
Dim buffLength As Integer = 2048
Dim buff(buffLength - 1) As Byte
' Opens a file stream (System.IO.FileStream) to read the file to be
' uploaded
Dim _FileStream As System.IO.FileStream = _FileInfo.OpenRead()
Try
' Stream to which the file to be upload is written
Dim _Stream As System.IO.Stream = _FtpWebRequest.GetRequestStream()
' Read from the file stream 2kb at a time
Dim contentLen As Integer = _FileStream.Read(buff, 0, buffLength)
' Till Stream content ends
Do While contentLen <> 0
' Write Content from the file stream to the FTP Upload Stream
_Stream.Write(buff, 0, contentLen)
contentLen = _FileStream.Read(buff, 0, buffLength)
Loop
' Close the file stream and the Request Stream
_Stream.Close()
_Stream.Dispose()
_FileStream.Close()
_FileStream.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message, "Upload Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles _
Button1.Click
UploadFile(OpenFileDialog1.FileName, "ftp://xxx.ddns.net/FTP/" + _
OpenFileDialog1.SafeFileName, "User", "Passwort")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles _
Button2.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then _
Exit Sub
'Label1.Text = OpenFileDialog1.FileName
Label1.Text = OpenFileDialog1.SafeFileName
Button1.Visible = True
Label2.Text = "ftp://xxx.ddns.net/FTP/" + OpenFileDialog1.SafeFileName
End Sub
End Class |