上传到ftp服务器上的文件没有复制完整的内容

时间:2014-05-17 07:37:34

标签: vb.net ftp

我正在使用netftp在ftp服务器上传文件,并按照示例上传文件。我的文件在服务器上创建但仍为空。我的代码如下

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

请帮忙。感谢

1 个答案:

答案 0 :(得分:0)

我使用ftp4j有类似的问题。我上传文件到服务器,但上传的文件有一个不同的大小。 解决方案是传输类型。 有ascii和二进制文件,你必须选择正确的传输类型。 我建议在你的图书馆文档中搜索。