Requirement, upload 1500 jpg images every night, the below code opens and closes a connection many times, I'm wondering if there is a better way.
...this is a code snippet, so there are variables here that are defined elsewhere
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
Some comments:
Yes, I know picCount is redundant...It was late at night.
ftpImagePath, picDir, ftpUsername, ftpPassword are all variables
Yes, this is unencrypted
This code works fine, I'm looking to optimize
Related Question: http://stackoverflow.com/questions/1772654/ftp-upload-multiple-files-without-disconnect-using-net