Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
2.5k views
in .NET FTP by (1.9k points)
Hi..

I am using the free component to upload directory contents to multiple FTP servers. I am using .NET 2, VB 2005. What is the best technique to do so?

Here is what I think:

- Put all the FTP IPs in an array
- Loop through them and in each iteration open a new FTPConnection instance.
- Use the instance to upload the folder contents.
- Close the ftp connection.
- Loop to the next IP in the array.

Is this the best solution or there a better one?

My second question is about logging. I need to generate a report with the upload results. Like the file name and the IP of the remote FTP server. Any hints?

Thanks
:)

3 Answers

0 votes
by (51.6k points)
Yes that solution would be a good way to do it.

It's worth nothing however that, since you are connecting to several different servers, you have the opportunity to make significant speed improvements by parallelizing the FTP tasks. You can do this by launching each FTP operation on a separate thread. .NET provides several different ways of doing this including using a background-worker, your own explicitly created threads or launching them on the CLR's own threadpool.

If you were using edtFTPnet/Express or edtFTPnet/PRO you'd be able to simplify your code by using asynchronous methods, such as BeginUpload(). You'd still need to create a new connection for each server, but you wouldn't need to worry about dealing with the threads yourself.

With respect to logging, edtFTPnet does provide extremely extensive logging - probably the best in its class - but this is more aimed towards diagnostics. You're probably best off recording the reporting details you're after yourself. You could use the events (Connected, Uploaded, etc) to trigger the recording of those details.

- Hans (EnterpriseDT)
0 votes
by (1.9k points)
Thanks for your reply. I am currently using the CLR's threadpool which is a great way for background processing. Now, as you mentioned I can use the events to do my own logging in my own format. However, when I use the Uploaded event, I face a problem. The problem is that the event arguments that are incorporated with the events do not include the host or server so that I can log which file was uploaded to which server. What do you advise?

Also when using express or pro editions with Async connections, what do the CallBack and State parameters signify and will it hurt to always pass NOTHING to them?
0 votes
by (51.6k points)
The sender argument holds a reference to the FTPConnection, so simply cast it and use it:
private void OnFileUploaded(object sender, FTPFileTransferEventArgs e)
{
    FTPConnection cxn = (FTPConnection)sender;
    string server = cxn.ServerAddress;
    ...
}

- Hans (EnterpriseDT)

Categories

...