Error while trying to play a video file uploaded to FTP server using FTPWebRequest

0

When I try to play a video uploaded to the FTP server using .net code, it says 'Can't play. Item is unplayable, please reacquire the content. 0xc00d36e5'.

Following is the code that I am using to upload a video file to the FTP server:

Protected Sub btnUpload_Click(sender As Object, e As EventArgs) Handles btnUpload.Click
    Try
        Dim posFile As HttpPostedFile = Nothing
        posFile = MyFile.PostedFile

        Dim strFileName As String = ""
        strFileName = posFile.FileName

        Dim ext As String = ""
        Dim fileName As String = ""

        ext = System.IO.Path.GetExtension(strFileName)
        fileName = "Vid_" + Now().ToString("yyyyMMddHHmmsss") & ext

        If MyFile.PostedFile.FileName = "" Then
            lblMsg.Text = "Please select a file to upload."
            lblMsg.Visible = True
            lblMsg.CssClass = "error"
        Else
            Dim fileBytes As Byte() = Nothing
            Using fileStream As New StreamReader(posFile.InputStream)
                fileBytes = Encoding.UTF8.GetBytes(fileStream.ReadToEnd())
                fileStream.Close()
            End Using

            Try
                Dim ftp As String = System.Configuration.ConfigurationManager.AppSettings("FtpMediaServerURL") //ftp://www.server.com

                Dim ftpFolder As String = "/media/"

                Dim request As FtpWebRequest = DirectCast(WebRequest.Create(ftp & ftpFolder & fileName), FtpWebRequest)
                request.Method = WebRequestMethods.Ftp.UploadFile

                request.Credentials = New NetworkCredential(System.Configuration.ConfigurationManager.AppSettings("FtpMediaServerUserName"), System.Configuration.ConfigurationManager.AppSettings("FtpMediaServerPassword"))
                request.ContentLength = fileBytes.Length
                request.UsePassive = True
                request.KeepAlive = False
                request.UseBinary = True
                request.ServicePoint.ConnectionLimit = fileBytes.Length
                request.EnableSsl = False

                Using requestStream As Stream = request.GetRequestStream()
                    requestStream.Write(fileBytes, 0, fileBytes.Length)
                    requestStream.Close()
                End Using

                Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
                response.Close()

                lblMsg.Text = "Your file has been uploaded successfully."
                lblMsg.Visible = True
                lblMsg.CssClass = "confirmation"

            Catch ex As Exception
                lblMsg.Text = "An Error occured while uploading your file. Please try again."
                lblMsg.Visible = True
                lblMsg.CssClass = "error"
            End Try
        End If
    Catch ex As Exception
       //Handle Exception
    End Try
End Sub

Can anyone point out what I am doing wrong or else I am missing anything?

asp.net
ftpwebrequest

1 Answer

0

Got this issue resolved! Instead of uploading the video file directly to the FTP server, what I did was to upload the video to a temporary location somewhere on the website server and then transfer it to the FTP server using the FTPWebRequest.

answered on Stack Overflow Nov 3, 2016 by randomstudious

User contributions licensed under CC BY-SA 3.0