0

我已经搜索但无法通过使用 VB.net 从本地系统上传文件来在我的网站上创建文件的任何真正解决方案

到目前为止,这是我的代码

        Dim rdr As New FileStream(ReSaveFile, FileMode.Open)
        Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://www.timemedian.com/display.txt"), HttpWebRequest)
        req.Method = "POST"
        ' you might use "POST"
        req.ContentLength = rdr.Length
        req.AllowWriteStreamBuffering = True

        Dim reqStream As Stream = req.GetRequestStream()

        Dim inData As Byte() = New Byte(rdr.Length - 1) {}

        ' Get data from upload file to inData 
        Dim bytesRead As Integer = rdr.Read(inData, 0, rdr.Length)

        ' put data into request stream
        reqStream.Write(inData, 0, rdr.Length)

        rdr.Close()
        req.GetResponse()

        ' after uploading close stream 
        reqStream.Close()

但我看不到错误。请帮忙

4

1 回答 1

0

我像这样使用ftp协议上传了文件

 Try
                       Dim mReq1 As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://ftp.websitename.com//" & SetID & ".pvx"), System.Net.FtpWebRequest)

                        mReq1.Credentials = New System.Net.NetworkCredential("username", "password")
                        mReq1.Method = System.Net.WebRequestMethods.Ftp.UploadFile

                        Dim MFile1() As Byte = System.IO.File.ReadAllBytes(ReSaveFile)

                        Dim mStream1 As System.IO.Stream = mReq1.GetRequestStream()
                        mStream1.Write(MFile1, 0, MFile1.Length)

                        mStream1.Close()
                        mStream1.Dispose()
                    Catch ex As Exception
                        MsgBox("Your file was not fully posted to the remote server. PVX Mail may not function properly")
                        Exit Sub
                    End Try
于 2013-10-11T13:13:37.773 回答