|
-
Jun 27th, 2010, 04:34 AM
#1
Thread Starter
Member
FTP uploading
Hello Everyone,
This site is amazing. I have learnt so much reading the many posts.
Does anyone have any suggestions as to what the best way of uploading a queue of files is?
I am currently creating a FTPWebrequest to handle my uploading (the webrequest section of my function is below). At the moment my code loops through this webrequest section for each file - giving the file path of each file in the string "CompleteLocalPath". For each file it creates a webrequest and giving the required file path, uploading the file using a file stream, and then closing the stream. This works, but seems to take quite a long time.
Can you recommend a more efficient way? Perhaps by using one webrequest but modifying the upload path?
Thank you very much for your help
Code:
Dim fwr As FtpWebRequest = FtpWebRequest.Create("ftp://ftp-server.com/directory/"+path.getfilename(completelocalpath))
fwr.Credentials = New NetworkCredential("username", "password")
fwr.Method = WebRequestMethods.Ftp.UploadFile
Dim requestStream As FileStream = File.OpenRead(CompleteLocalPath)
Dim buffer(requestStream.Length) As Byte
requestStream.Read(buffer, 0, buffer.Length)
requestStream.Close()
requestStream = Nothing
fwr.GetRequestStream.Write(buffer, 0, buffer.Length)
fwr = Nothing
-
Jun 27th, 2010, 04:43 AM
#2
Re: FTP uploading
From the looks of things you don't really need th extra control provided by the FtpWebRequest, so it would be simpler to use a WebClient and call UploadFile or even just call My.Computer.Network.UploadFile.
To upload multiple files in parallel, you could use the ThreadPool to upload each file on a different thread, calling UploadFile for each one. Alternatively, you could use the WebClient and call UploadFileAsync, which will inherently upload on a secondary thread. Note that, if you use a WebClient, you will need one for each file.
-
Jun 27th, 2010, 11:31 AM
#3
Thread Starter
Member
Re: FTP uploading
Thanks a lot,
I'm going with the multi-threading and it is almost working I think. I will post the code when I have it correctly
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|