예제 #1
0
        public Byte[] ConvertObjectToStream(ProductCatalogImport o)
        {
            string str = SerializeObject <ProductCatalogImport>(o);

            var _byte = StringToUTF8ByteArray(str);

            return(_byte);
        }
예제 #2
0
 public string SerializeObject <t>(ProductCatalogImport obj)
 {
     try
     {
         string        xmlString     = null;
         MemoryStream  memoryStream  = new MemoryStream();
         XmlSerializer xs            = new XmlSerializer(typeof(ProductCatalogImport));
         XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
         xs.Serialize(xmlTextWriter, obj);
         memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
         xmlString    = ByteArrayToUTF8String(memoryStream.ToArray()); return(xmlString);
     }
     catch
     {
         return(string.Empty);
     }
 }
예제 #3
0
        public bool CreateFileSFTP(string host, string username, string password, string _path, string folder, string fileName, ProductCatalogImport products)
        {
            var _stream = ConvertObjectToStream(products);

            bool downloadresult = false;

            string fullfolderPath = _path + "/" + folder;
            string currentTime    = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second;
            string fullPath       = fullfolderPath + "/" + fileName + "-" + currentTime.Trim() + ".xml";

            using (SftpClient sftp = new SftpClient(host, username, password))
            {
                try
                {
                    sftp.Connect();

                    if (!sftp.Exists(fullfolderPath))
                    {
                        sftp.CreateDirectory(fullfolderPath);
                    }
                    // byte[] results = System.Text.Encoding.ASCII.GetBytes("hello");
                    var stream = new MemoryStream();
                    using (var ms = new MemoryStream(_stream))
                    {
                        sftp.BufferSize = (uint)ms.Length;     // bypass Payload error large files
                        sftp.UploadFile(ms, fullPath);
                    }


                    sftp.Disconnect();
                }
                catch (Exception er)
                {
                    //   Console.WriteLine("An exception has been caught " + er.ToString());
                }
            }
            return(downloadresult);
            //       String LocalDestinationPath = HttpContext.Current.Server.MapPath("~/DownloadFile");
            //         Helper.Utility.FTPDownload(LocalDestinationPath, "test.txt", ApplicationEngine.FTP_Host+ ApplicationEngine.FTP_File_Path+ "/test.txt", ApplicationEngine.FTP_User_Name, ApplicationEngine.FTP_Password);
        }