|
Hi,
I want to upload browsed file to the ftp server but getting this error
Sub UploadFile()
Try
Dim fileName As String = FulFile.PostedFile.FileName
Dim requestFTP As WebRequest = WebRequest.Create("ftp://...................." & fileName)
requestFTP.Credentials = New NetworkCredential("userid", "password")
requestFTP.Method = WebRequestMethods.Ftp.UploadFile
Dim fStream As FileStream = FulFile.PostedFile.InputStream 'Error:Unable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream'.
Dim bufferLength As Integer = 2048
Dim buffer As Byte() = New Byte(bufferLength - 1) {}
Dim uploadStream As Stream = requestFTP.GetRequestStream()
Dim contentLength As Integer = fStream.Read(buffer, 0, bufferLength)
While contentLength <> 0
uploadStream.Write(buffer, 0, contentLength)
contentLength = fStream.Read(buffer, 0, bufferLength)
End While
uploadStream.Close()
fStream.Close()
requestFTP = Nothing
LblMsg.Text = "File Uploading Is SuccessFull..."
Catch ep As Exception
LblMsg.Text = ep.Message
End Try
End Sub
|
|
|
|
|
I'm not sure how the error message could be any clearer:
- the
HttpPostedFile.InputStream property is a System.Web.HttpInputStream , which inherits from System.IO.Stream ; - you are attempting to store it in a variable of type
System.IO.FileStream , which is a different type of System.IO.Stream .
Change your fStream variable to be a System.IO.Stream :
Dim fStream As Stream = FulFile.PostedFile.InputStream
Also, you're still not calling the GetResponse method on your requestFTP object. If you don't call that method, your request will never be sent.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
GetResponse and requestFTP what are these and how can we upload using GetResponse and requestFTP
bcoz it showing that
Network Error (tcp_error)
A communication error occurred: ""
The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time.
|
|
|
|
|
requestFTP is a variable in the code you just posted.
GetResponse is a method on the FtpWebRequest type.
The error you keep posting to different threads is most likely related to a timeout or firewall issue, and is nothing to do with the question you asked in the first post of this thread.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|