How do I can upload serveral files at same time? - WeOnlyDo Discussion board

How do I can upload serveral files at same time? (General questions)

by yinpengxiang, Tuesday, August 25, 2009, 10:45 (5568 days ago)

I want to upload serveral files at same time, I used the wodFtpDLXComClass in FtpDLX.
I readed the help file and I know I can't upload multi-files in a component instance at same time, I must wait until the first file uploaded then upload next. So I create serveral wodFtpDLXComClass instance in serveral thread (each thread has a wodFtpDLXComClass instance), but they seemed not work as I expect.

I want to upload 3~5 files at same time but one by one, How to do it? thanks.

Re: How do I can upload serveral files at same tim

by wodDamir, Tuesday, August 25, 2009, 11:40 (5568 days ago) @ yinpengxiang

Hi,

When using component in non-blocking mode, you need to use Done event in order to call each method. When Done event is triggered, it means that the previoous method finished executing, and it's ok to call next one.

In blocking mode, however, you can simply do something like this:

[code]// Set blocking mode
ftp1.Blocking = true;
// Connect to server
ftp1.Connect();

// Do getfile calls
for(int i=0;i<3;i++)
{
ftp1.Putfile( localpath , remotepath );
}
[/code]

Or, you can simply call Putfiles, which would upload all the files from some directory, recursively.

Hope this helps.

Regards,
Damba

Re: How do I can upload serveral files at same tim

by yinpengxiang, Tuesday, August 25, 2009, 12:13 (5568 days ago) @ wodDamir

I used the block model the progress event is not work before the progress is 100 .
the code you offered for uploading is the one by one way, I want to upload files at same time, as the following code, but the result is not my expect result:
void DownloadFiles(string[] files)
{
while(localFiles.Count>0)
{
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(Dowork));
t.Start();
}
}
void Dowork()
{
if (localFiles.Count == 0) return;
string file = localFiles[0];
localFiles.Remove(file);

wodFtpDLXComClass ftp = new wodFtpDLXComClass();
ftp.Blocking = true;
ftp.Connect(hostName, port, protocol);
ftp.PutFile(file, remoteFilePath);
}

Re: How do I can upload serveral files at same tim

by wodDamir, Tuesday, August 25, 2009, 13:05 (5568 days ago) @ yinpengxiang

Hi,

When using blocking mode, you shouldn't use events, and vice versa. Also, when using threading, you should keep in mind that you should use apartment threading model (component and events declared and used in same thread).

I would suggest that you create your own class, and implement component there. Then call that class in multiple threads.

Can you try that?

regards,
Damba

Re: How do I can upload serveral files at same tim

by yinpengxiang, Tuesday, August 25, 2009, 15:18 (5568 days ago) @ wodDamir

Damba,
Thanks, It is important I must use apartment threading model (component and events declared and used in same thread).
I have used the blocking=false, and have fired events, but it seemed that the real transport working thread is only one, it means that the connect method of the second ftp component instance can't start until the first ftp transport completed.

regards,
Shareach

Re: How do I can upload serveral files at same tim

by wodDamir, Tuesday, August 25, 2009, 16:02 (5568 days ago) @ yinpengxiang

Shareach,

I'm not really sure what you mean. The behaviour you described is typical blocking mode behaviour, where component's thread would be blocked until released.

When using Blocking = false, this shouldn't occur. However, Blocking property needs to be set before calling the Connect method.

Regards,
Damba