private static int RunDownload(string [] targetArgs, string[] paramArgs) { string remotePath; string localPath; if (targetArgs.Length < 3) { Console.Error.WriteLine("download needs more 2 arguments."); Console.Error.WriteLine("download (remotepath) (localpath)"); return(0); } remotePath = targetArgs[1]; remotePath = remotePath.Replace('\\', '/'); localPath = targetArgs[2]; if (!localPath.Contains(':') && !localPath.StartsWith(@"\\")) { localPath = Path.GetFullPath(localPath); } if (!localPath.StartsWith(@"\\")) { localPath = ItemControl.GetLongFilename(localPath); } Console.Error.WriteLine("download"); Console.Error.WriteLine("remote: " + remotePath); Console.Error.WriteLine("local: " + ItemControl.GetOrgFilename(localPath)); ReloadType reload = ReloadType.Reload; foreach (var p in paramArgs) { switch (p) { case "cache": Console.Error.WriteLine("(--cache: no reload)"); reload = ReloadType.Cache; break; } } var job = JobControler.CreateNewJob(JobClass.ControlMaster); job.DisplayName = "Download"; JobControler.Run(job, (j) => { try { var j2 = InitServer(j); j2.Wait(ct: j.Ct); var target = FindItems(remotePath, ct: j.Ct, reload: reload); if (target.Count() < 1) { j.ResultAsObject = 2; return; } string remotePathBase = null; if (remotePath.IndexOfAny(new[] { '*', '?' }) < 0) { remotePathBase = ItemControl.GetCommonPath(target); } else { remotePathBase = GetBasePath(remotePath); } target = RemoveDup(target); ConsoleJobDisp.Run(); var j3 = target .Where(x => x.ItemType == RemoteItemType.File) .Select(x => RemoteServerFactory.PathToItem(x.FullPath, ReloadType.Reload).Result) .Select(x => ItemControl.DownloadFile(Path.Combine(localPath, ItemControl.GetLocalFullPath(x.FullPath, remotePathBase)), x, j, true)); var j4 = target .Where(x => x.ItemType == RemoteItemType.Folder) .Select(x => RemoteServerFactory.PathToItem(x.FullPath, ReloadType.Reload).Result) .Select(x => ItemControl.DownloadFolder(Path.GetDirectoryName(Path.Combine(localPath, ItemControl.GetLocalFullPath(x.FullPath, remotePathBase))), new[] { x }, j, true)); foreach (var jx in j3.Concat(j4).ToArray()) { j.Ct.ThrowIfCancellationRequested(); jx.Wait(ct: j.Ct); } job.ResultAsObject = 0; } catch (OperationCanceledException) { job.ResultAsObject = -1; } catch (Exception ex) { Console.Error.WriteLine("error: " + ex.ToString()); job.ResultAsObject = 1; } }); try { job.Wait(ct: job.Ct); } catch (OperationCanceledException) { } TSviewCloudConfig.Config.ApplicationExit = true; Console.Out.Flush(); return((job.ResultAsObject as int?) ?? -1); }