在.NET2003中使用VB.Net通过Ftp发送文件
我想使用vb通过FTP在服务器上发送文件。net(VS2003,framework 1.1)引发异常 WEBCLIENT请求期间发生异常 同样的代码在.NET2008中运行良好。我不知道为什么它会抛出异常在.NET2003中使用VB.Net通过Ftp发送文件,vb.net,ftp,Vb.net,Ftp,我想使用vb通过FTP在服务器上发送文件。net(VS2003,framework 1.1)引发异常 WEBCLIENT请求期间发生异常 同样的代码在.NET2008中运行良好。我不知道为什么它会抛出异常 Imports System.Data.SqlClient Imports System.Text Imports Microsoft.VisualBasic Imports System.Net.WebRequest Imports System.Net.WebClient Imports
Imports System.Data.SqlClient
Imports System.Text
Imports Microsoft.VisualBasic
Imports System.Net.WebRequest
Imports System.Net.WebClient
Imports System.Net
Imports System.IO
If (Directory.Exists(directoryPath)) Then
arrFileList = Directory.GetFiles(directoryPath) '''Getting All files
Else
MessageBox.Show("Directory not Exist")
End If
For i As Integer = 0 To i < arrFileList.Length - 1
Try
Dim fileName As String = arrFileList.GetValue(i)
Dim toUpload As New FileInfo(fileName)
Dim client As New WebClient
Dim nc As New NetworkCredential("xxxx", "xxxx")
Dim addy As Uri
addy = New Uri("ftp://1xx.xx.xxx.xxx/HYPOSII_FTP/Test/" & toUpload.Name.ToString())
client.Credentials = nc
Dim arrReturn As Byte() = client.UploadFile(addy.ToString(), fileName) //This Line Throwing error
MessageBox.Show("File Uploaded Sucessfully")
FLAG = True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Next
导入System.Data.SqlClient
导入系统文本
导入Microsoft.VisualBasic
导入System.Net.WebRequest
导入System.Net.WebClient
导入系统.Net
导入System.IO
如果(Directory.Exists(directoryPath)),则
arrFileList=Directory.GetFiles(directoryPath)“获取所有文件”
其他的
MessageBox.Show(“目录不存在”)
如果结束
对于i As Integer=0到i
您的For
循环应将i的读取为arrFileList的整数=0。长度-1
;拥有我感谢回复David…我的循环工作正常,但在上传时抛出异常。你可以查看我提到评论的那一行。对不起-我不是说更改For
循环可以解决上传问题。这只是一个语法问题,不允许循环一直运行。由于.NET 1.1没有在框架中内置FTP客户端,因此它依赖操作系统来进行传输,并且如果底层Windows API返回错误代码,它只是某种报告。对于.NET 1.1 FTP应用程序,我们在edtFTPnet()方面取得了很好的成功。感谢回复David。。。。我查看了1.1的框架,发现它不支持来自windows应用程序的FTP客户端或Webclient请求…感谢edtFTPnet建议,但我的客户端尚未准备好投资。。。无论如何,我找到了解决这个问题的另一种方法。现在我通过使用批处理文件实现了这个目标。大卫再次感谢你的支持……非常感谢。