For some reason i am getting this error when I try to upload to my ftp:
This happens at the GetRequestStream() portion of the code. here is my code:Code:The underlying connection was closed: The server committed a protocol violation.
Code:Private Sub FTPUpload(ByVal p_FilePath As String, ByVal p_FTPServer As String, ByVal p_FileNameOnServer As String, _ ByVal p_Username As String, ByVal p_Password As String) 'Reading file into a byte array Dim file As Byte() file = System.IO.File.ReadAllBytes(p_FilePath) 'Request Dim req As System.Net.FtpWebRequest req = DirectCast(System.Net.WebRequest.Create("ftp://" + p_FTPServer + "/" + p_FileNameOnServer), System.Net.FtpWebRequest) 'Credentials Dim credentials As New System.Net.NetworkCredential(p_Username, p_Password) req.Credentials = credentials 'Request Method req.Method = System.Net.WebRequestMethods.Ftp.UploadFile 'uploading file onto FTP server Dim stream As System.IO.Stream stream = req.GetRequestStream() stream.Write(file, 0, file.Length) stream.Close() End Sub




Reply With Quote