EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TElSimpleFTPSClient.Receive acting strange

Posted: 01/14/2014 06:12:22
by Michael Mankus (Standard support level)
Joined: 01/09/2014
Posts: 6

First off, I'm using the .NET 4.0 desktop library.

I want to download all of the files within a given directory on my FTP server (I'm using the example application as my server - FTPSServer.NET_VS2010).

First thing my client does is get a list of all the files on the server using:

Client.GetFileList(String.Empty, AllFilesInfo);

Then I proceed to download each file one after the other. I am using the Receive method because I need to report progress, and I also need to support resume. It looks like the DownloadFile method does not support reporting progress. Here is how I download the files:

foreach (TElFTPFileInfo info in AllFilesInfo)
    string NewFilename = String.Format("{0}_{1}", FilenamePrefix, info.Name);
    DataStream = new FileStream(NewFilename, FileMode.Append, FileAccess.Write);
    totalFileBytes = info.Size;
    resumeFileBytes = DataStream.Length;

    if (resumeFileBytes == totalFileBytes) // The file is already downloaded

    bool Error = false;
        Client.Receive(info.Name, resumeFileBytes, totalFileBytes);
    catch (Exception)
        Error = true;

    if (Error || CancelRequest || CloseRequest) // For some reason we need to stop
        e.Cancel = true;
        e.Result = false;

This works fine as long as I'm not resuming any files.

However, if I AM trying to resume a file, the file I'm resuming will download correctly but the next file does not download correctly.

Here is an example:

Let's say I have two files I need to download. The first file is 65 MB and the second file is 76 MB. I already have 19 MB of the first file downloaded and then I run my method.

What happens is that the remaining 46 MB of the first file gets correctly downloaded. The file checks out and is correct. Great.

It then proceeds to (try to) download the second file in its entirety. But the Receive method stops after downloading 57 MB (instead of the full 76 MB of the second file). This is interesting because that is exactly 19 MB short of the total file size of the second file - which just happens to be how much of the first file was downloaded before we began the method.

If I run my routine again, it skips the first file since it is already fully downloaded. And then it attempts to get the remaining 19 MB of file two. But the finished file is corrupt. So I am not sure what exactly those first 57 MB of the second file are. Or where they are coming from.

I can’t seem to figure out what is happening with the Receive method but it isn’t working properly.

I tried to force the method to do specific things, for example I did this:

Client.Receive(info.Name, 1024, 10 * 1024 * 1024);

So I’m telling it to download 10 MB starting 1 KB into the file. After it downloads those 10 MB, the Receive method throws an EElFTPSError Exception with message “Control channel transfer error”. What the heck is happening?

Is my understanding of what this method does incorrect?

Or, is there a better way to download a file that supports reporting progress and resuming of files?
Posted: 01/14/2014 06:24:26
by Vsevolod Ievgiienko (Team)

Thank you for contacting us.

It looks like the DownloadFile method does not support reporting progress.

Does OnProgress event is not fired? Or it reports invalid results? This method supports resume mode that you need.
Posted: 01/14/2014 06:32:26
by Michael Mankus (Standard support level)
Joined: 01/09/2014
Posts: 6

Ah I see that it supports both resume and reporting progress. Great.

But resuming is still giving me trouble.

if (File.Exists(NewFilename))
    Client.DownloadFile(info.Name, NewFilename, SBTypes.TSBFileTransferMode.ftmResume, -1);
    Client.DownloadFile(info.Name, NewFilename, SBTypes.TSBFileTransferMode.ftmOverwrite);

I'm doing this. But if the file exists, the DownloadFile method just ends (no error or exception) but doesn't actually do anything. It just skips that file and moves onto the next.
Posted: 01/14/2014 06:52:37
by Michael Mankus (Standard support level)
Joined: 01/09/2014
Posts: 6

This is really the last sticking point before my organization (Federal Aviation Administration) buys a license. It seems no matter how I try to resume a file, it doesn't work properly.

long test = (new FileInfo(NewFilename)).Length;
Client.DownloadFile(info.Name, NewFilename, SBTypes.TSBFileTransferMode.ftmResume, test);

That doesn't work and this doesn't work:

Client.DownloadFile(info.Name, NewFilename, SBTypes.TSBFileTransferMode.ftmResume, -1);

In both cases, the DownloadFile method is simply ended without an error or exception. And the OnProgress method is not called.

The DownloadFile method is working fine when it needs to grab the entire file (as well as OnProgress). But resume is still an issue.
Posted: 01/14/2014 07:06:39
by Vsevolod Ievgiienko (Team)

Please try to set Client.UseSIZECmd to 'false' and try resumption again.
Posted: 01/14/2014 07:50:08
by Michael Mankus (Standard support level)
Joined: 01/09/2014
Posts: 6

Changing this property produced the same results.
Posted: 01/14/2014 07:53:27
by Michael Mankus (Standard support level)
Joined: 01/09/2014
Posts: 6

Here are my client settings:

Client = new TElSimpleFTPSClient();
Client.OnControlReceive += Client_OnControlReceive;
Client.OnProgress += Client_OnProgress;
Client.Address = address;
Client.Port = 21;
Client.Username = username;
Client.Password = password;
Client.Versions = SBSSLConstants.Unit.sbSSL3;
Client.UseSSL = false;
Client.EncryptDataChannel = true;
Client.AuthCmd = SBSimpleFTPS.Unit.acAuto;
Client.PassiveMode = false;
Client.SSLMode = TSBSSLMode.smExplicit;
Client.UseSIZECmd = false;
Posted: 01/14/2014 08:32:27
by Vsevolod Ievgiienko (Team)

I've moved this topic to Helpdesk. You'll receive a notification by e-mail. Please post there your client project that we can use to reproduce the problem.



Topic viewed 1050 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!