Exemplo n.º 1
0
            /// <summary>
            /// Function to start a download
            /// </summary>
            /// <param name="orgremoteFile"></param>
            /// <param name="remotefile"></param>
            /// <param name="localfile"></param>
            public void Download(string orgremoteFile, string remotefile, string localfile)
            {
                string name   = System.IO.Path.GetFileName(remotefile);
                string folder = orgremoteFile.Substring("remote:".Length);

                folder = folder.Substring(0, folder.Length - (name.Length + 1));
                string[] subitems = folder.Split(new char[] { '?' });
                if (subitems[4] == string.Empty)
                {
                    subitems[4] = "/";
                }
                bool   fileExists = false;
                string tmpDir     = string.Empty;

                FTPFile[] files;
                try
                {
                    tmpDir = subitems[4];
                    Connection.ChDir(tmpDir);
                    files = Connection.DirDetails(); //(tmpDir);
                    for (int i = 0; i < files.Length; ++i)
                    {
                        FTPFile file = files[i];
                        if (file.Dir)
                        {
                            continue;
                        }
                        if (String.Compare(file.Name, name, true) == 0)
                        {
                            fileExists = true;
                            break;
                        }
                    }
                    if (!fileExists)
                    {
                        if (Connection.Connected)
                        {
                            Connection.QuitImmediately();
                        }
                        Busy = false;
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("FtpConnectionCache:Download {0}", ex.Message);
                    return;
                }

                Log.Debug("FTPConnection: Download {0} from {1} to {2}", remotefile, tmpDir, localfile);
                LocalFileName          = localfile;
                RemoteFileName         = remotefile;
                OriginalRemoteFileName = orgremoteFile;
                BackgroundWorker worker = new BackgroundWorker();

                worker.DoWork += new DoWorkEventHandler(StartDownLoad);
                worker.RunWorkerAsync();
            }