0

我想将文件上传到我的 FTP 服务器,凭据的值是 userlabel passlabel 和 servlabel,这些都是凭据的相应标签。 Passlabel 和 userlabel 实际上是混合的。 pass 是用户,而 userlabel 是密码。我想实现一个prgressbar,但我不知道该怎么做有人请帮忙

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

Private Sub BW_DoWork(ByVal sender As System.Object, 
                      ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BW.DoWork

    Dim clsRequest As System.Net.FtpWebRequest = _
            DirectCast(System.Net.WebRequest.Create(ServLabel.Text & 
                                                    TextBox1.Text), 
                                                    System.Net.FtpWebRequest)

    clsRequest.Credentials = New System.Net.NetworkCredential(PassLabel.Text, UserLabel.Text)
    clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

    ' read in file...
    Dim bFile() As Byte = System.IO.File.ReadAllBytes(txtFile.Text)

    ' upload file...
    Dim clsStream As System.IO.Stream = _
        clsRequest.GetRequestStream()

    clsStream.Write(bFile, 0, bFile.Length)
    clsStream.Close()
    clsStream.Dispose()

    BW.ReportProgress(clsStream.Position.ToString)

    MsgBox("File Is Now In Database", MsgBoxStyle.OkOnly, "Upload Complete")

End Sub
4

1 回答 1

0

您可以只将数组的一部分传递bFileclsStream.Write()方法并重复它,直到所有部分都写入流。

PartsCount = 100

PartsLength = bFile.Length \ PartsCount     
If PartLength * PartsCount = bFile.Length Then PartsCount -= 1

For i as Integer = 0 to PartsCount
   If i <> PartsCount Then
      clsStream.Write(bFile, i * PartsLength, PartLength)
   Else
      clsStream.Write(bFile, i * PartsLength, bFile.Length - (i * PartsLength))
   End If 

   clsStream.Flush()

   'calculate the progess here
Next

clsStream.Close()
于 2013-02-03T18:24:15.040 回答