我正在尝试使用 WebClient 将文件上传到 ftp 服务器,但我不断收到下面列出的相同错误:远程服务器返回错误:(401)未经授权。
正如您在代码示例中看到的那样,我在 try catch 表单中尝试了 4 种不同的上传方法。你能帮我解决这个问题吗?
Dim wc As New WebClient
wc.Credentials = New NetworkCredential(ftp.username, ftp.password)
Try 'UploadFile Method (String, String)
Dim dddd As Byte() = wc.UploadFile("https://ftp.something/something/something/", serverpath)
Catch ex1 As Exception
Try 'UploadFile Method (Uri, String)
Dim dddd As Byte() = wc.UploadFile(ftp.myUri, serverpath)
Catch ex2 As Exception
Try 'UploadFile Method(Of String, String, String)
Dim dddd As Byte() = wc.UploadFile("https://ftp.something/something/something/", "POST", serverpath)
Catch ex33 As Exception
Try 'UploadFile Method (Uri, String, String)
Dim dddd As Byte() = wc.UploadFile(ftp.myUri, "POST", serverpath)
Catch ex As Exception
End Try
End Try
End Try
End Try