private FtpInfo ReadFtpConfig() { FtpInfo ftpInfo = new FtpInfo(); if (txt_Host.Text != string.Empty) { ftpInfo.host = txt_Host.Text; } if (txt_Id.Text != string.Empty) { ftpInfo.id = txt_Id.Text; } if (txt_Password.Text != string.Empty) { ftpInfo.password = txt_Password.Text; } if (txt_Port.Text != string.Empty) { ftpInfo.port = Int32.Parse(txt_Port.Text); } ftpInfo.passiveMode = true; ftpInfo.remotePath = "/"; ftpInfo.lFiles = new List <string>(); return(ftpInfo); }
private void viewRemoteListView(FtpInfo info, ftp ftpClient, string remotePath) { string[] dirInfo = ftpClient.directoryListDetailed(remotePath); string dir_name = string.Empty; string dir_option = string.Empty; string Temp = string.Empty; txt_remothPath.Text = remotePath; if (listBox_Remote.Items.Count > 0) { listBox_Remote.Items.Clear(); } listBox_Remote.Items.Add(".."); foreach (string dir in dirInfo) { if (dir.Length > 1) { //dir -> "drwxr-xr-x 1 ftp ftp 0 Sep 07 17:04 folder1" dir_name = dir.Substring(dir.LastIndexOf(':') + 4); dir_option = dir.Substring(0, dir.IndexOf(' ')); if (dir_name.IndexOf('/') > 0) { Temp = dir_name.Substring(dir.LastIndexOf('/') + 1); listBox_Remote.Items.Add(Temp); } else { listBox_Remote.Items.Add(dir_name); } } } }
//접속 버튼 private void btn_Connect_Click(object sender, EventArgs e) { //Debug txt_Host.Text = @"localhost"; txt_Id.Text = @"test"; txt_Password.Text = @"test"; //FTP Config FtpInfo info = ReadFtpConfig(); ftp ftpClient = new ftp(string.Format(@"ftp://{0}/{1}", info.host, info.remotePath), info.id, info.password); //Remote Directory List viewRemoteListView(info, ftpClient, "/"); }
//다운로드 버튼 ( '>' ) private void btn_Download_Click(object sender, EventArgs e) { string fileName = string.Empty; string localFullPath = string.Empty; FtpInfo info = ReadFtpConfig(); ftp ftpClient = new ftp(string.Format(@"ftp://{0}/{1}", info.host, info.remotePath), info.id, info.password); fileName = listBox_Remote.SelectedItem.ToString(); info.lFiles.Add(fileName); localFullPath = string.Format(@"{0}{1}", txt_localpath.Text, fileName); ftpClient.download(fileName, localFullPath); //Local Directory List viewLocalListView(txt_localpath.Text); }
//업로드 버튼 ( '<' ) private void btn_upload_Click(object sender, EventArgs e) { string fileName = string.Empty; string localFullPath = string.Empty; string remoteFullPath = string.Empty; FtpInfo info = ReadFtpConfig(); ftp ftpClient = new ftp(string.Format(@"ftp://{0}/{1}", info.host, info.remotePath), info.id, info.password); fileName = listBox_Local.SelectedItem.ToString(); info.lFiles.Add(fileName); localFullPath = string.Format(@"{0}{1}", txt_localpath.Text, fileName); remoteFullPath = string.Format(@"{0}/{1}", txt_remothPath.Text, fileName); ftpClient.upload(remoteFullPath, localFullPath, true, true); //Remote Directory List viewRemoteListView(info, ftpClient, txt_remothPath.Text); }
//Remote 더블클릭 이벤트 (경로 이동) private void listBox_Remote_DoubleClick(object sender, EventArgs e) { string localPath = string.Empty; string[] temp = txt_remothPath.Text.Split('/'); FtpInfo info = ReadFtpConfig(); ftp ftpClient = new ftp(string.Format(@"ftp://{0}/{1}", info.host, info.remotePath), info.id, info.password); if (listBox_Remote.SelectedIndex == 0 && temp.Count() > 1 && temp[1] != string.Empty) { for (int i = 0; i < temp.Count() - 1; i++) { if (temp[i] != string.Empty) { if (info.remotePath == "/") { info.remotePath += string.Format(@"{0}", temp[i]); } else { info.remotePath += string.Format(@"/{0}", temp[i]); } } } viewRemoteListView(info, ftpClient, info.remotePath); } else if (listBox_Remote.SelectedIndex > 0) { if (txt_remothPath.Text == "/") { info.remotePath = string.Format(@"{0}{1}", txt_remothPath.Text, listBox_Remote.SelectedItem); } else { info.remotePath = string.Format(@"{0}/{1}", txt_remothPath.Text, listBox_Remote.SelectedItem); } viewRemoteListView(info, ftpClient, info.remotePath); } }
protected override void Process() { CurrentLanguage = PrimaryLanguage; var Soap = new AssortmentService(); #if CACHE if (!File.Exists(String.Format(ImagesCacheFile, Connector.ConnectorID, PrimaryLanguage.LanguageID))) { ImagesXml = XDocument.Parse(Soap.GetAssortmentImages(Connector.ConnectorID)); ImagesXml.Save(String.Format(ImagesCacheFile, Connector.ConnectorID, PrimaryLanguage.LanguageID)); } else { ImagesXml = XDocument.Load(String.Format(ImagesCacheFile, Connector.ConnectorID, PrimaryLanguage.LanguageID)); } #else ImagesXml = XDocument.Parse(Soap.GetAssortmentImages(Connector.ConnectorID)); #endif SBLicenseManager.TElSBLicenseManager m = new SBLicenseManager.TElSBLicenseManager(); m.LicenseKey = "8F1317CD48AC4E68BABA5E339D8B365414D7ADA0289CA037E9074D29AD95FF3EC5D796BEFF0FBADB3BD82F48644C9EB810D9B5A305E0D2A1885C874D8BF974B9608CE918113FBE2AA5EEF8264C93B25ABEA98715DB4AD265F47CE02FC9952D69F2C3530B6ABAAA4C43B45E7EF6A8A0646DA038E34FBFB629C2BF0E83C6B348726E622EBD52CA05CF74C68F1279849CCD0C13EA673916BA42684015D658B8E7626F15BD826A4340EDB36CE55791A051FDBCF9FA1456C3B5008AD9990A0185C0EA3B19F9938CB7DA1FE82736ED4C7A566D4BFD53411E8380F4B020CB50E762520EFAE190836FD253B00DB18D4A485C7DC918AA4DCEC856331DD231CC8DC9C741C3"; FtpInfo ftpInfo = SftpHelper.GetFtpInfo(Connector); Logger.DebugFormat("Exporting images for language '{0}'", CurrentLanguage.Language.Name); SortedDictionary <string, catalog_product_entity> currentProducts; SortedDictionary <string, eav_attribute> attributeList; using (var helper = new MagentoMySqlHelper(Connector.Connection)) { attributeList = helper.GetAttributeList(PRODUCT_ENTITY_TYPE_ID); currentProducts = helper.GetSkuList(); } var products = (from i in ImagesXml.Root.Elements("Products").Elements("ProductMedia") where i.Attribute("ManufacturerID") != null orderby Convert.ToInt32(i.Attribute("ProductID").Value) descending group i by i.Attribute("ManufacturerID").Value into grouped select grouped).ToList(); var directoryStructureRecords = (from i in ImagesXml.Root.Elements("Products").Elements("ProductMedia") // this catches the changes in webservice structure let urlAttribute = i.Attribute("Url") let uri = (urlAttribute != null) ? new Uri(urlAttribute.Value) : new Uri(i.Value) select new { FirstLevel = uri.Segments.Last().Substring(0, 1), SecondLevel = uri.Segments.Last().Substring(1, 1) }).GroupBy(x => x.FirstLevel).ToDictionary(x => x.Key, y => y.Select(z => z.SecondLevel).Distinct()); var dirClient = SftpHelper.GetSFTPClient(ftpInfo); foreach (var kv in directoryStructureRecords) { SftpHelper.EnsurePath(dirClient, ftpInfo.FtpPath + kv.Key); //if (!dirClient.Exists(kv.Key)) // dirClient.MakeDirectory(kv.Key); foreach (var sl in kv.Value) { //if (!dirClient.Exists(kv.Key + "/" + sl)) // dirClient.MakeDirectory(kv.Key + "/" + sl); SftpHelper.EnsurePath(dirClient, ftpInfo.FtpPath + kv.Key + "/" + sl); } } dirClient.Close(true); int totalImages = products.Select(x => x.Count()).Sum(); int totalRecords = products.Count; int totalProcessed = 0; if (totalRecords == 0) { Logger.DebugFormat("Finished exporting images for language '{0}'", CurrentLanguage.Language.Name); return; } ParallelOptions options = new ParallelOptions() { MaxDegreeOfParallelism = 8 }; Parallel.ForEach(Partitioner.Create(0, totalRecords), options, (range, loopState) => { TElSimpleSFTPClient client = SftpHelper.GetSFTPClient(ftpInfo); try { using (var helper = new AssortmentHelper(Connector.Connection, Version)) { for (int index = range.Item1; index < range.Item2; index++) { var product = products[index]; var sku = product.Key.Trim(); catalog_product_entity entity; if (!currentProducts.TryGetValue(sku, out entity)) { continue; } List <string> currentPaths = new List <string>(); //helper.ResetGallery(entity, 0); var sequencedImages = product.OrderBy(x => Convert.ToInt32(x.Attribute("Sequence").Value)).ToList(); var thumbnailImage = sequencedImages.FirstOrDefault(c => c.Attribute("IsThumbnailImage") != null && Convert.ToBoolean(c.Attribute("IsThumbnailImage").Value)); int?thumbImageIdx = null; if (thumbnailImage != null) { thumbImageIdx = sequencedImages.IndexOf(thumbnailImage); } for (int idx = 0; idx < sequencedImages.Count; idx++) { var image = sequencedImages[idx]; int position = Convert.ToInt32(image.Attribute("Sequence").Value) + 1; int storeid = 0; // this catches the changes in webservice structure var sourceUri = (image.Attribute("Url") != null) ? new Uri(image.Attribute("Url").Value) : new Uri(image.Value); var label = image.Attribute("Description") != null ? image.Attribute("Description").Value : string.Empty; string fileName = sourceUri.Segments.Last(); string linuxPath = String.Format(@"/{0}/{1}/{2}", fileName.Substring(0, 1), fileName.Substring(1, 1), fileName.Replace(" ", "")); #if DEBUG //sourceUri = new Uri(sourceUri.AbsoluteUri.Replace("localhost", "10.172.26.1")); sourceUri = new Uri(sourceUri.AbsoluteUri.Replace("localhost", "172.16.250.94")); #endif string path = DownloadImage(sourceUri, client, ftpInfo.FtpPath, Logger); if (path != null) { helper.AddImageToGallery(entity.entity_id, storeid, path, position, label, Logger); if (idx == 0) { helper.SyncAttributeValue(attributeList["image"].attribute_id, PRODUCT_ENTITY_TYPE_ID, 0, entity.entity_id, path); helper.SyncAttributeValue(attributeList["small_image"].attribute_id, PRODUCT_ENTITY_TYPE_ID, 0, entity.entity_id, path); helper.SyncAttributeValue(attributeList["image_label"].attribute_id, PRODUCT_ENTITY_TYPE_ID, 0, entity.entity_id, label); } if (thumbImageIdx.HasValue && thumbImageIdx.Value == idx) { helper.SyncAttributeValue(attributeList["thumbnail"].attribute_id, PRODUCT_ENTITY_TYPE_ID, 0, entity.entity_id, path); } currentPaths.Add(path); } } var currentImages = helper.GetGalleryItems(entity); CleanupGallery(helper, entity, currentImages, currentPaths, client, ftpInfo.FtpPath); Interlocked.Increment(ref totalProcessed); //Logger.DebugFormat("Connections : {0}", ftp.ConnectionOpen); //Logger.DebugFormat("Processed {0}", totalProcessed); if (totalProcessed % 100 == 0) { Logger.DebugFormat(String.Format("Processed {0} of {1} products", totalProcessed, totalRecords)); } } } } catch (Exception e) { Logger.Error("Image uploader error ", e); } }); Logger.DebugFormat("Finished exporting images for language '{0}'", CurrentLanguage.Language.Name); }
public FtpServiceProvider() { this.Ftp = new FtpInfo(); }
public TaskManager(ConfigInfo info, FtpInfo ftpInfo) : this(info) { this.FtpInfo = ftpInfo; }
public void Test() { string root = Path.GetDirectoryName(Environment.CurrentDirectory); string token = System.Environment.GetEnvironmentVariable("SACLOUD_TOKEN"); string secret = System.Environment.GetEnvironmentVariable("SACLOUD_SECRET"); string zone = System.Environment.GetEnvironmentVariable("SACLOUD_ZONE"); API api = API.Authorize(token, secret, zone); string name = "!cs_nunit-" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "-" + (new Regex(@"-.+")).Replace(System.Guid.NewGuid().ToString(), ""); string description = "This instance was created by saklient.cs NUnit"; string tag = "saklient-test"; // create/upload { IsoImage iso = api.IsoImage.Create(); iso.Name = name; iso.Description = description; iso.Tags = new List <string> { tag }; iso.SizeMib = 5120; iso.Save(); // FtpInfo ftp = iso.FtpInfo; Assert.IsNotNull(ftp.HostName); Assert.IsNotNull(ftp.User); Assert.IsNotNull(ftp.Password); FtpInfo ftp2 = iso.OpenFtp(true).FtpInfo; Assert.IsNotNull(ftp2.HostName); Assert.IsNotNull(ftp2.User); Assert.IsNotNull(ftp2.Password); Assert.AreNotEqual(ftp.Password, ftp2.Password); // Console.WriteLine("FTPS: " + ftp2.User + ":" + ftp2.Password + "@" + ftp2.HostName); ServicePointManager.ServerCertificateValidationCallback = (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true; Uri uri = new Uri("ftp://" + ftp2.HostName + "/image.iso"); FtpWebRequest ftpReq = FtpWebRequest.Create(uri) as FtpWebRequest; ftpReq.EnableSsl = true; ftpReq.Credentials = new NetworkCredential(ftp2.User, ftp2.Password); ftpReq.Method = WebRequestMethods.Ftp.UploadFile; // ftpReq.KeepAlive = true; // ftpReq.UseBinary = true; // ftpReq.UsePassive = true; // ftpReq.ContentLength = 1024 * 256; Stream stream = ftpReq.GetRequestStream(); Random rnd = new Random(); byte[] buffer = new byte[1024]; for (int i = 0; i < 256; i++) { rnd.NextBytes(buffer); stream.Write(buffer, 0, buffer.Length); } stream.Close(); FtpWebResponse ftpRes = ftpReq.GetResponse() as FtpWebResponse; Console.WriteLine("{0}: {1}", ftpRes.StatusCode, ftpRes.StatusDescription); ftpRes.Close(); iso.CloseFtp(); // iso.Destroy(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////// // insert/eject { // search iso images Console.WriteLine("searching iso images..."); List <IsoImage> isos = api.IsoImage .WithNameLike("CentOS 6. 64bit") .WithSharedScope() .Limit(1) .Find(); Assert.Greater(isos.Count, 0); IsoImage iso = isos[0]; // create a server Console.WriteLine("creating a server..."); Server server = api.Server.Create(); server.Name = name; server.Description = description; server.Tags = new List <string> { tag }; server.Plan = api.Product.Server.GetBySpec(1, 1); server.Save(); // insert iso image while the server is down Console.WriteLine("inserting an ISO image to the server..."); server.InsertIsoImage(iso); Assert.AreEqual(iso.Id, server.Instance.IsoImage.Id); // eject iso image while the server is down Console.WriteLine("ejecting the ISO image from the server..."); server.EjectIsoImage(); Assert.IsNull(server.Instance.IsoImage); // boot Console.WriteLine("booting the server..."); server.Boot(); Thread.Sleep(3); // insert iso image while the server is up Console.WriteLine("inserting an ISO image to the server..."); server.InsertIsoImage(iso); Assert.AreEqual(iso.Id, server.Instance.IsoImage.Id); // eject iso image while the server is up Console.WriteLine("ejecting the ISO image from the server..."); server.EjectIsoImage(); Assert.IsNull(server.Instance.IsoImage); // stop Thread.Sleep(1); Console.WriteLine("stopping the server..."); if (!server.Stop().SleepUntilDown()) { Assert.Fail("サーバが正常に停止しません"); } // delete the server Console.WriteLine("deleting the server..."); server.Destroy(); } }
//-------------------------------------------------------------------------------------------- /// <summary> /// Saves the configuration. /// </summary> public void SaveConfiguration() { File.WriteAllText(Path.Combine(CurrentAppConfigDir, FTPInfo.FTP_INFO_FILE), FtpInfo.Serialize()); File.WriteAllText(Path.Combine(CurrentAppConfigDir, SmtpInfo.SMTP_INFO_FILE), SmtpInfo.Serialize()); File.WriteAllText(Path.Combine(CurrentAppConfigDir, PMASystemAnalyzerInfo.PMA_INFO_FILE), SystemAnalyzerInfo.Serialize()); File.WriteAllText(Path.Combine(CurrentAppConfigDir, LoggerInfo.LOGGER_CONFIG_FILE), Logger.SerializedLoggerInstance()); File.WriteAllText(Path.Combine(CurrentAppConfigDir, PMAInfo.PMA_INFO_FILE), PMAInfoObj.Serialize()); if (PMAUsers.ListPMAUserInfo != null) { File.WriteAllText(Path.Combine(CurrentAppConfigDir, PMAUsers.PMA_USERS_FILE), PMAUsers.Serialize()); } File.WriteAllText(Path.Combine(CurrentAppConfigDir, PMAServerManagerInfo.PMA_SERVER_MANAGER_INFO), PMAServerManagerInfo.Serialize()); }