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

Can I create a threaded DownloadFile() method using the free version of ftp net component?

I tried threading it, but it seems that it is still waiting for the previous thread to finish the downloading/uploading of file.

I want to create this using just a single connection.

thanks.

IANIAN

11 Answers

0 votes
by (51.6k points)
Yes, you can create your own threaded application using edtFTPnet. Multithreaded programming is one of those things that appears to be hard before you start, but once you get going you find out that it's even harder than you thought it was going to be. This is why Microsoft have introduced their asynchronous programming paradigm which isolates the user from many of the more complex aspects of multithreaded programming.

- Hans (EDT)
0 votes
by (540 points)
Yes, you can create your own threaded application using edtFTPnet. Multithreaded programming is one of those things that appears to be hard before you start, but once you get going you find out that it's even harder than you thought it was going to be. This is why Microsoft have introduced their asynchronous programming paradigm which isolates the user from many of the more complex aspects of multithreaded programming.

- Hans (EDT)


can you lead me to a very good example of asynchronous programming?
please....

thanks again :)
0 votes
by (51.6k points)
I may have mislead you a little here. You can only use MS's asynchronous programming paradigm if the API you are using supports it. edtFTPnet doesn't support it, but edtFTPnet/PRO does - it's one of the major features.

In edtFTPnet/PRO you can do things like:
        private void transferButton_click(object sender, EventArgs e)
        {
            proFTPConnection.BeginConnect(null, null);
            proFTPConnection.BeginChangeWorkingDirectory("/directory", null, null);
            proFTPConnection.BeginDownloadFile(@"C:\MyDir\MyFile.dat", "MyFile.dat", null, null);
            proFTPConnection.BeginClose(new AsyncCallback(OnFinished), null);
        }

        private void OnFinished(IAsyncResult res)
        {
            MessageBox.Show("Done");
        }

This will connect to the server, change directory, download a file and then disconnect. It will do all this in the background. In other words, each of the Begin...() methods will return immediately so that transferButton_click() returns instantly and your GUI doesn't freeze. Once the connection is closed, the OnFinished method will be called so that the message box can be popped up informing the user that everything's done.

However, since edtFTPnet doesn't have asynchronous methods, you'll need to use a worker thread and the multithreaded-signalling classes that you can find in System.Threading.

- Hans (EDT)
0 votes
by (540 points)
Hi I Tried also threading in ftp.net but it seems that it also do the downloading of file one by one and also the program hangs most of the time.

well if you said that this is supported in the ftp.net pro version then I might consider buying it.

But please answer my questions below.

1. Is there a feature in the pro version that can download a single file threaded? so that it can dowload a single file fast?
2. Is there a feature also that downloads for example i want to download a directory and all its sub directory and files will also be downloaded and also threaded?
3. Also, what do you mean by 12 months subscription?
Does it mean that by 1 year my software will expire and cannot be used anymore? or does ot mean that I will not only have an updated software at the end of 1 year?

thank you so much.
0 votes
by (51.6k points)
1. Is there a feature in the pro version that can download a single file threaded? so that it can dowload a single file fast?

Could you please explain what you mean by "download a single file threaded"? I don't think I understand.
2. Is there a feature also that downloads for example i want to download a directory and all its sub directory and files will also be downloaded and also threaded?

Yes, the pro version supports directory downloads. It can do it either by wildcards (e.g. ftpConnection.DownloadMultiple(directory, "*.txt")) or by user-defined filters. Filters work using callbacks like this:
...
ftpConnection.DownloadMultiple(directory, new FileFilter(IsFileSmall));
...
public bool IsFileSmall(FTPFile file)
{
   return file.Size<=maxSize;
}

The directory download methods, like all the other methods in ProFTPConnection, have asynchronous versions. So, in the example above you would use BeginDownloadMultiple(). The files are downloaded one-by-one though. The FTP protocol does not allow multiple files to be downloaded on a single connection. ProFTPConnection represents a single connection, so it can only download files one at a time.
3. Also, what do you mean by 12 months subscription? Does it mean that by 1 year my software will expire and cannot be used anymore? or does ot mean that I will not only have an updated software at the end of 1 year?

It's the latter. You can of course use the software for as long as you want, but you are only entitled to support and updates while your subscription is current.

- Hans (EDT)
0 votes
by (540 points)
I may have mislead you a little here. You can only use MS's asynchronous programming paradigm if the API you are using supports it. edtFTPnet doesn't support it, but edtFTPnet/PRO does - it's one of the major features.

In edtFTPnet/PRO you can do things like:
        private void transferButton_click(object sender, EventArgs e)
        {
            proFTPConnection.BeginConnect(null, null);
            proFTPConnection.BeginChangeWorkingDirectory("/directory", null, null);
            proFTPConnection.BeginDownloadFile(@"C:\MyDir\MyFile.dat", "MyFile.dat", null, null);
            proFTPConnection.BeginClose(new AsyncCallback(OnFinished), null);
        }

        private void OnFinished(IAsyncResult res)
        {
            MessageBox.Show("Done");
        }

This will connect to the server, change directory, download a file and then disconnect. It will do all this in the background. In other words, each of the Begin...() methods will return immediately so that transferButton_click() returns instantly and your GUI doesn't freeze. Once the connection is closed, the OnFinished method will be called so that the message box can be popped up informing the user that everything's done.

However, since edtFTPnet doesn't have asynchronous methods, you'll need to use a worker thread and the multithreaded-signalling classes that you can find in System.Threading.

- Hans (EDT)


Hi I tried finding the method you posted above like "BeginConnect" but I cannoty find it in edtFTPNetPro.dll in the trial version.
what seems to be the problem?
0 votes
by (540 points)
1. Is there a feature in the pro version that can download a single file threaded? so that it can dowload a single file fast?

Could you please explain what you mean by "download a single file threaded"? I don't think I understand.

What I mean here is for example I have a big document file that is 1gigabyte in size. Of course the donwloading would be slow since it has a big size. What I mean is, can it be downloaded in multiple chunks? for example one thread download 1 to 1000 of file pointer the other thread download 1001 to 2000 of the file pointer and so on at the same time?


The directory download methods, like all the other methods in ProFTPConnection, have asynchronous versions. So, in the example above you would use BeginDownloadMultiple(). The files are downloaded one-by-one though. The FTP protocol does not allow multiple files to be downloaded on a single connection. ProFTPConnection represents a single connection, so it can only download files one at a time.

The software LeechFTP can download multiple files at the same time. So i think FTP protocol supports downloading of multiple file at the same time in as ingle connection. Am I wrong with this? Have u tried using LeechFTP?
0 votes
by (51.6k points)
What I mean here is for example I have a big document file that is 1gigabyte in size. Of course the donwloading would be slow since it has a big size. What I mean is, can it be downloaded in multiple chunks? for example one thread download 1 to 1000 of file pointer the other thread download 1001 to 2000 of the file pointer and so on at the same time?

You can do this using the Restart(long) method. It's normally used to restart a transfer that has been interrupted, but I'm pretty sure it'd work in your scenario as well. Just keep in mind that, depending on the network environment, using multiple connections might not actually speed up the transfer since they're all sharing the same bandwidth.

I just realized that Restart is only available in FTPClient and hasn't made it into the FTPConnection class yet. I'm sorry about this :oops:. We will add it ASAP.
The software LeechFTP can download multiple files at the same time. So i think FTP protocol supports downloading of multiple file at the same time in as ingle connection. Am I wrong with this? Have u tried using LeechFTP?

I haven't tried using LeechFTP, but FileZilla has similar functionality. What they do though, is that they have a pool of up to, say, five connections available. They then allocate each FTP operation to a connection that's not currently busy. At the moment this sort of functionality is not available internally within edtFTPnet/PRO, though it wouldn't be too hard to imlement on top of ProFTPConnection.
I tried finding the method you posted above like "BeginConnect" but I cannoty find it in edtFTPNetPro.dll in the trial version.
what seems to be the problem?

Make sure you're using ProFTPConnection and not ProFTPClient. Also, make sure you're using version 2.0 of the library since ProFTPConnection did not exist in previous versions.

- Hans (EDT)
0 votes
by (540 points)
HI.

In FTPConnection,
How will I know the number of bytes that I have already uploaded in the remote server?

For example I upload A.zip and i want to know the progress of the uploading of that file.

Thanks.
0 votes
by (51.6k points)
Use the BytesTransferred event.

- Hans (EDT)

Categories

...