要求,每晚上传1500 jpg图片,下面的代码打开和关闭多次连接,我想知道是否有更好的方法。上传多个FTP文件
...这是一个代码片段,所以这里在别处
Dim picClsRequest = DirectCast(System.Net.WebRequest.Create(ftpImagePath), System.Net.FtpWebRequest)
Dim picClsStream As System.IO.Stream
Dim picCount As Integer = 0
For i = 1 To picPath.Count - 1
picCount = picCount + 1
log("Sending picture (" & picCount & " of " & picPath.Count & "):" & picDir & "/" & picPath(i))
picClsRequest = DirectCast(System.Net.WebRequest.Create(ftpImagePath & "/" & picPath(i)), System.Net.FtpWebRequest)
picClsRequest.Credentials = New System.Net.NetworkCredential(ftpUsername, ftpPassword)
picClsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
picClsRequest.UseBinary = True
picClsStream = picClsRequest.GetRequestStream()
bFile = System.IO.File.ReadAllBytes(picDir & "/" & picPath(i))
picClsStream.Write(bFile, 0, bFile.Length)
picClsStream.Close()
Next
一些意见所界定还存在变数:
是的,我知道picCount是多余的...这是在后期晚。
ftpImagePath,picDir,ftpUsername,ftpPassword都是变量
是的,这是不加密的
此代码工作正常,我在寻找优化
相关问题:FTP Upload multiple files without disconnect using .NET
注:我有这个代码的问题是,它保持打开一个新的FTP连接。每次运行此应用时,它都会打开并关闭1500次。 – Markus 2010-03-15 18:33:17