user1990 user1990 - 1 year ago 180
ASP.NET (C#) Question

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

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
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"
Dim fileBytes As Byte() = Nothing
Using fileStream As New StreamReader(posFile.InputStream)
fileBytes = Encoding.UTF8.GetBytes(fileStream.ReadToEnd())
End Using

Dim ftp As String = System.Configuration.ConfigurationManager.AppSettings("FtpMediaServerURL") //

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)
End Using

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

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download