login about faq

Hi. I am writing a C# FTP program. I'm a hobbyist PHP programmer, and I used to instantiate a PDO connection to the MySQL server in functions that needed SQL access. I then read that it's better to pass the already open PDO object to the function.

I was curious, is that the same with the FTP object? I'm doing this (a bit pared down but gets the gist):

using (Chilkat.Ftp2 ftp = new Ftp2()) {
  if (ftp.Connect()) {
    Targets.Clear(); DownloadQueue.Clear();
    Write("Scanning accounting projects ...");
    ProcessTargets(ftp, GetChildren(ftp, "/Projects/Acct"));

    Write("Scanning engineering projects ...");
    ProcessTargets(ftp, GetChildren(ftp, "/Projects/Eng"));

    Write("Scanning sales projects ...");
    ProcessTargets(ftp, GetChildren(ftp, "/Projects/Sales"));

    if (DownloadQueue.Count > 0) {
      trd = new Thread(new ThreadStart(DownloadThread));
      trd.Start();
    }

    ftp.Disconnect();
  }
}

void ProcessTargets(Chilkat.Ftp2 ftp, ArrayList targets) {
  try {
    foreach (string target in targets) {
      Write("Processing " + target + " ...");
      (blah blah ftp stuff)
      Application.DoEvents();
    }
  } catch (Exception ex) {
    Write("** EXCEPTION (PT): " + ex.Message);
  }
}

Is that proper? Thanks!

asked Jul 10 '15 at 22:33

Strahan's gravatar image

Strahan
1113


I don't think there should be any problem passing around a reference to an FTP object with an connection, at least as long as the destination function is running in the same thread as where you created the FTP object.

There might be an issues with you DoEvents call though if you are performing other actions against the same FTP object in other events - they may get fired and produce unexpected results.

Chilkat would have a definitive answer though, so if you have an active support license, it might be worth checking in through the official support channel.

link

answered Jul 11 '15 at 11:08

jpbro's gravatar image

jpbro ♦
1.1k2618

1

Thanks. I figured it was probably OK, just wanted to be sure. Everything is in the same thread, it's just a one file at a time downloader. Thanks again!

(Jul 15 '15 at 22:52) Strahan
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×131

Asked: Jul 10 '15 at 22:33

Seen: 463 times

Last updated: Jul 15 '15 at 22:52

powered by OSQA