uploaded copy didn't write content in it

May 17, 2014 at 8:32 AM
i downloaded latest version and tried example code to upload a file in ftp server. File is created on ftp but empty. code is as given below
Sub BeginOpenWriteCallback(ar As IAsyncResult)
    Dim conn As FtpClient = TryCast(ar.AsyncState, FtpClient)
    Dim istream As Stream = Nothing, ostream As Stream = Nothing
    Dim buf As Byte() = New Byte(8192) {}
    Dim read As Integer
    Dim input = Server.MapPath("../UploadedMedia/5.mp4")
    Try
        If conn Is Nothing Then
            Throw New InvalidOperationException("The FtpControlConnection object is null!")
        End If



        istream = New FileStream(input, FileMode.Open, FileAccess.Read)



        While ((read = istream.Read(buf, 0, buf.Length)) > 0)
            ostream.Write(buf, 0, read)

        End While

        ostream = conn.EndOpenWrite(ar)

    Catch ex As Exception
        Console.WriteLine(ex.ToString())
    Finally
        If istream IsNot Nothing Then
            istream.Close()
        End If

        If ostream IsNot Nothing Then
            ostream.Close()
        End If

        m_reset.[Set]()
    End Try
End Sub
Please help what am i doing wrong. Thanks
Coordinator
May 17, 2014 at 12:38 PM

From: alihassan316321

i downloaded latest version and tried example code to upload a file in ftp server. File is created on ftp but empty. code is as given below
Sub BeginOpenWriteCallback(ar As IAsyncResult)
    Dim conn As FtpClient = TryCast(ar.AsyncState, FtpClient)
    Dim istream As Stream = Nothing, ostream As Stream = Nothing
    Dim buf As Byte() = New Byte(8192) {}
    Dim read As Integer
    Dim input = Server.MapPath("../UploadedMedia/5.mp4")
    Try
        If conn Is Nothing Then
            Throw New InvalidOperationException("The FtpControlConnection object is null!")
        End If



        istream = New FileStream(input, FileMode.Open, FileAccess.Read)



        While ((read = istream.Read(buf, 0, buf.Length)) > 0)
            ostream.Write(buf, 0, read)

        End While

        ostream = conn.EndOpenWrite(ar)

    Catch ex As Exception
        Console.WriteLine(ex.ToString())
    Finally
        If istream IsNot Nothing Then
            istream.Close()
        End If

        If ostream IsNot Nothing Then
            ostream.Close()
        End If

        m_reset.[Set]()
    End Try
End Sub
Please help what am i doing wrong. Thanks