Ejemplo n.º 1
0
        /// <summary>
        /// List a remote directory in the console.
        /// </summary>
        public List <string> ListFiles(string remoteDirectory, ILog log)
        {
            var connectionInfo = SshClient.GetConnectionInfo(_config);

            var fileList = new List <string>();

            using (var sftp = new Renci.SshNet.SftpClient(connectionInfo))
            {
                try
                {
                    sftp.Connect();

                    var files = sftp.ListDirectory(remoteDirectory);

                    foreach (var file in files)
                    {
                        fileList.Add(file.Name);
                    }

                    sftp.Disconnect();
                }
                catch (Renci.SshNet.Common.SshConnectionException e)
                {
                    throw new RemoteConnectionException(e.Message, e);
                }
                catch (Exception e)
                {
                    log?.Error($"SftpClient.ListFiles :: Error listing files {e}");
                }
            }
            return(fileList);
        }
Ejemplo n.º 2
0
        public Dictionary <string, byte[]> GetSecurityFilePack()
        {
            String[] SecurityFileNames = new String[] {
                @"/usr/local/platform/conf/platformConfig.xml",
                @"/usr/local/platform/.security/CCMEncryption/keys/dkey.txt"
            };
            Dictionary <String, byte[]> oSecurityFilePack = new Dictionary <String, byte[]>();

            sftpClient.Connect();
            if (sftpClient.IsConnected)
            {
                foreach (String sFileName in SecurityFileNames)
                {
                    MemoryStream memStream = new MemoryStream();

                    sftpClient.DownloadFile(sFileName, memStream);

                    byte[] fileBytes = new byte[memStream.Length];
                    memStream.Seek(0, SeekOrigin.Begin);
                    memStream.Read(fileBytes, 0, (int)memStream.Length);
                    oSecurityFilePack[sFileName] = fileBytes;
                    //Console.Write("{0}\n", Functions.encoding.GetString(xmlDataBytes));
                }
                sftpClient.Disconnect();
            }
            else
            {
                // Error - not connected
            }

            return(oSecurityFilePack);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Disconnects from the SFTP server.
 /// </summary>
 public void Disconnect()
 {
     try
     {
         _sftpClient.Disconnect();
     }
     catch (Exception)
     {
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Disconnects from the SFTP server.
 /// </summary>
 public void Disconnect()
 {
     try
     {
         _sftpClient.Disconnect();
     }
     catch
     {
     }
 }
Ejemplo n.º 5
0
 private static void DisconnectDocumi()
 {
     if (IsActiveConnection())
     {
         Utils.CLogger.WriteLog(" disconnecting from " + SFTP_HOST);
         SFTPClient.Disconnect();
         SFTPClient.Dispose();
         SFTPClient = null;
         Utils.CLogger.WriteLog(" EXITING ");
         Environment.Exit(0);
     }
 }
Ejemplo n.º 6
0
        // Start is called before the first frame update
        IEnumerator Start()
        {
            sshManager = GetComponent <SshManager>();
            using (var client = new Renci.SshNet.SftpClient("192.168.0.11", "root", "alpine"))
            {
                client.Connect();

                Debug.Log("Connected.");
                yield return(StartCoroutine(sshManager.GetAllFilePaths(client, "/private/var/mobile/Containers/Data/Application/D7BD557F-D731-4D5B-88C2-325B46CA1F97")));

                client.Disconnect();
            }
        }
Ejemplo n.º 7
0
        public bool CopyLocalToRemote(Dictionary <string, byte[]> files, ILog log)
        {
            var isSuccess = true;

            // upload new files as destination user

            var connectionInfo = SshClient.GetConnectionInfo(_config);

            using (var sftp = new Renci.SshNet.SftpClient(connectionInfo))
            {
                try
                {
                    sftp.Connect();

                    foreach (var dest in files)
                    {
                        try
                        {
                            sftp.WriteAllBytes(dest.Key, dest.Value);
                        }
                        catch (SftpPathNotFoundException exp)
                        {
                            // path not found, folder is probably wrong
                            log?.Error($"SftpClient :: Failed to copy file. Check that the full path to {dest} is valid and that 'sudo' is not required to perform file copy. {exp}");

                            // failed to copy the file. TODO: retries
                            isSuccess = false;
                            break;
                        }
                        catch (Exception exp)
                        {
                            log?.Error($"SftpClient :: Failed to perform CopyLocalToRemote [{connectionInfo.Host}:{connectionInfo.Port}]: {exp}");

                            // failed to copy the file. TODO: retries
                            isSuccess = false;
                            break;
                        }
                    }
                    sftp.Disconnect();
                }
                catch (Exception exp)
                {
                    isSuccess = false;
                    log?.Error($"SftpClient :: Failed to perform CopyLocalToRemote [{connectionInfo.Host}:{connectionInfo.Port}]: {exp}");
                }
            }

            return(isSuccess);
        }
Ejemplo n.º 8
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                if (client != null)
                {
                    if (client.IsConnected)
                    {
                        client.Disconnect();
                    }
                    client.Dispose();
                }
            }

            disposed = true;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// GetAudioFileName
        /// </summary>
        /// <param name="drv"></param>
        /// <returns></returns>
        public static string GetAudioFileName(getScorecardData_Result drv)
        {
            // If this scorecard is for website, just return the website

            int Id;

            try
            {
                Id = drv.X_ID;
            }
            catch (Exception ex)
            {
                Id = drv.F_ID;
            }

            //DataTable sc_id = GetTable("select *, (select bypass from userextrainfo where username = '******') as bypass from xcc_report_new  join scorecards  on xcc_report_new.scorecard = scorecards.id join app_settings  on app_settings.appname = xcc_report_new.appname where xcc_report_new.id = " + Id);
            using (CC_ProdEntities dataContext = new CC_ProdEntities())
            {
                var sc_id = dataContext.GetAudioFileName(HttpContext.Current.User.Identity.Name, Id).FirstOrDefault();
                if (sc_id != null)
                {
                    if (sc_id.bypass.ToString() == "True" & sc_id.onAWS.ToString() == "True")
                    {
                        return("http://files.callcriteria.com" + sc_id.audio_link);
                    }
                    if (sc_id.onAWS.ToString() == "True")
                    {
                        string    audio_link = sc_id.audio_link;
                        IAmazonS3 s3Client;
                        s3Client = new AmazonS3Client(System.Configuration.ConfigurationManager.AppSettings["CCAWSAccessKey"], System.Configuration.ConfigurationManager.AppSettings["CCCAWSSecretKey"], Amazon.RegionEndpoint.APSoutheast1);

                        GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest();
                        GetPreSignedUrlRequest URL_REQ  = new GetPreSignedUrlRequest();
                        URL_REQ.BucketName = "callcriteriasingapore" + Strings.Left(audio_link, audio_link.LastIndexOf("/")).Replace("/audio2/", "/audio/");
                        URL_REQ.Key        = audio_link.Substring(audio_link.LastIndexOf("/") + 1);
                        URL_REQ.Expires    = DateTime.Now.AddHours(1);
                        return(s3Client.GetPreSignedURL(URL_REQ));
                    }

                    if (sc_id.review_type == "website")
                    {
                        return("/point1sec.mp3");
                    }
                    if (sc_id.stream_only.ToString() == "True")
                    {
                        return(sc_id.audio_link);
                    }
                }

                if (Strings.Left(drv.audio_link.ToString(), 6) == "/audio" & (Strings.Right(drv.audio_link.ToString(), 4) == ".mp3" | Strings.Right(drv.audio_link.ToString(), 4) == ".mp4" | Strings.Right(drv.audio_link.ToString(), 4) == ".gsm"))
                {
                    //try
                    //{
                    //    TimeSpan call_len = new TimeSpan(0, 0, Convert.ToInt32(GetMediaDuration("http://files.callcriteria.com" + drv.audio_link)) / 2);   // tlf.Properties.Duration
                    //    DateTime call_time = Convert.ToDateTime("12/30/1899") + call_len;
                    //    UpdateTable("update XCC_REPORT_NEW set call_time = '" + call_time.ToString() + "' where ID = (select review_id from form_score3  where ID = " + Id + ")");
                    //    UpdateTable("update form_score3 set call_length = '" + call_len.TotalSeconds + "' where ID = " + Id);
                    //    return "http://files.callcriteria.com" + drv.audio_link.ToString(); // already converted, send it back
                    //}
                    //catch (Exception ex)
                    //{
                    //    return "http://files.callcriteria.com" + drv.audio_link.ToString();
                    //}
                }

                // thinks it's downloaded, but file's not there, get the orignal file and download again
                if (Strings.Left(drv.audio_link.ToString(), 6) == "/audio" & (Strings.Right(drv.audio_link.ToString(), 4) == ".mp3" | Strings.Right(drv.audio_link.ToString(), 4) == ".mp4" | Strings.Right(drv.audio_link.ToString(), 4) == ".gsm"))
                {
                    // Email_Error("trying to reload " & drv.Item("audio_link").ToString)
                    // See if session ID has data
                    //wav_dt = GetTable("select * from wav_data  where session_id = '" + drv.SESSION_ID + "'");
                    var wav_dt = dataContext.WAV_DATA.Where(x => x.session_id == drv.SESSION_ID).FirstOrDefault();
                    if (wav_dt == null)
                    {
                        //wav_dt = GetTable("select * from wav_data  where filename like '%" + drv.SESSION_ID + "%'");
                    }
                    if (wav_dt != null)
                    {
                        drv.audio_link = wav_dt.filename;
                    }
                }

                string session_id;
                if (drv.SESSION_ID.ToString().IndexOf(" ") > 0)
                {
                    session_id = Strings.Left(drv.SESSION_ID.ToString(), drv.SESSION_ID.ToString().IndexOf(" "));
                }
                else
                {
                    session_id = drv.SESSION_ID;
                }

                string phone         = drv.phone.ToString();
                string this_filename = drv.audio_link.ToString();

                string call_date = drv.call_date.ToString().Substring(0, drv.call_date.ToString().IndexOf(" ")).Replace("/", "_");
                if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath("/audio/" + drv.appname.ToString() + "/" + call_date + "/")))
                {
                    System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("/audio/" + drv.appname.ToString() + "/" + call_date + "/"));
                }
                if (drv.audio_link.ToString() != "")
                {
                    if (Strings.Left(drv.audio_link.ToString(), 4) == "http" | Strings.Left(drv.audio_link.ToString(), 6) == "/audio" | Strings.Left(drv.audio_link.ToString(), 3) == "ftp")
                    {
                        this_filename = drv.audio_link.ToString().Replace(" ", "%20");
                    }
                    else
                    {
                        this_filename = drv.url_prefix + (drv.audio_link.ToString().Replace(" ", "%20"));
                    }


                    string file_ending = Strings.Right(this_filename, 4).ToLower();


                    if ((this_filename.IndexOf("@") > -1 | this_filename.IndexOf("http") > -1) & Strings.Left(this_filename, 3) != "ftp" & Strings.Left(this_filename, 4) != "sftp" & Strings.Left(this_filename, 6) != "/audio")
                    {
                        // Email_Error(this_filename)
                        System.Net.WebClient WebClient_down = new System.Net.WebClient();

                        WebClient_down.Credentials = new System.Net.NetworkCredential(drv.recording_user.ToString(), drv.record_password.ToString(), "");

                        try
                        {
                            WebClient_down.DownloadFile(this_filename, HttpContext.Current.Server.MapPath("/audio/" + drv.appname.ToString() + "/" + call_date + "/" + session_id + file_ending));
                        }
                        catch (Exception ex)
                        {
                            HttpContext.Current.Response.Write("File not found, refresh page." + this_filename + " to " + HttpContext.Current.Server.MapPath("/audio/" + drv.appname.ToString() + "/" + call_date + "/" + session_id + file_ending) + ex.Message);
                            //Email_Error(HttpContext.Current.Server.MapPath("/audio/" + drv.appname.ToString() + "/" + call_date + "/" + session_id + file_ending) + ex.Message);
                            HttpContext.Current.Response.Redirect("listen.aspx");
                        }


                        while (!!WebClient_down.IsBusy)
                        {
                            System.Threading.Thread.Sleep(100);
                        }
                    }

                    if (Strings.Left(this_filename, 6) == "ftp://")
                    {
                        WebClient ftpc = new WebClient();
                        ftpc.Credentials = new System.Net.NetworkCredential(drv.audio_user.ToString(), drv.audio_password.ToString(), "");

                        try
                        {
                            System.IO.File.Delete(@"d:\wwwroot\audio\" + drv.appname.ToString() + @"\" + call_date + @"\" + session_id + file_ending);
                        }
                        catch (Exception ex)
                        {
                        }

                        try
                        {
                            ftpc.DownloadFile(this_filename, @"d:\wwwroot\audio\" + drv.appname.ToString() + @"\" + call_date + @"\" + session_id + file_ending);
                            System.Threading.Thread.Sleep(500);
                        }
                        catch (Exception ex)
                        {
                            HttpContext.Current.Response.Write(@"d:\wwwroot\audio\" + drv.appname.ToString() + @"\" + call_date + @"\" + session_id + file_ending + " " + ex.Message + "<br><br><br>");
                            HttpContext.Current.Response.End();
                        }

                        while (!!ftpc.IsBusy)
                        {
                            System.Threading.Thread.Sleep(100);
                        }
                    }

                    if (Strings.Left(this_filename, 7) == "sftp://")
                    {
                        try
                        {
                            Renci.SshNet.SftpClient sftp_new = new Renci.SshNet.SftpClient(drv.recording_user.ToString().Substring(7), Convert.ToInt32(drv.audio_link.ToString()), drv.audio_user.ToString(), drv.audio_password.ToString());
                            sftp_new.Connect();

                            System.IO.FileStream dest_file = new System.IO.FileStream(@"d:\wwwroot\audio\" + drv.appname.ToString() + @"\" + call_date + @"\" + session_id + file_ending, FileMode.OpenOrCreate);

                            sftp_new.DownloadFile(this_filename.Substring(Strings.Len(drv.recording_user)).Replace("%20", " "), dest_file);
                            sftp_new.Disconnect();
                            sftp_new.Dispose();
                            dest_file.Close();
                            dest_file.Dispose();
                        }
                        catch (Exception ex)
                        {
                            HttpContext.Current.Response.Write(ex.Message + "<br>");
                            HttpContext.Current.Response.Write(@"d:\wwwroot\audio\" + drv.appname.ToString() + @"\" + call_date + @"\" + session_id + file_ending + "<br>");
                            HttpContext.Current.Response.Write(this_filename.Substring(Strings.Len(drv.recording_user)).Replace("%20", " "));
                            HttpContext.Current.Response.End();
                        }
                        int max_wait = 0;
                        while (!System.IO.File.Exists(HttpContext.Current.Server.MapPath("/audio/" + drv.appname.ToString() + "/" + call_date + "/" + session_id + file_ending)) | max_wait == 100)
                        {
                            System.Threading.Thread.Sleep(100);
                            max_wait += 1;
                        }
                    }
                    if (file_ending == ".mp3" | file_ending == ".mp4")
                    {
                        this_filename = HttpContext.Current.Server.MapPath("/audio/" + drv.appname.ToString() + "/" + call_date + "/" + session_id + file_ending);
                    }
                    else
                    {
                        try
                        {
                            this_filename = HttpContext.Current.Server.MapPath("/audio/" + drv.appname.ToString() + "/" + call_date + "/" + session_id + file_ending);
                        }
                        catch (Exception ex)
                        {
                            return("");
                        }
                        string output           = "";
                        string out_error        = "";
                        string destination_file = HttpContext.Current.Server.MapPath("/audio/" + drv.appname.ToString() + "/" + call_date + "/" + session_id + ".mp3");
                        //RunFFMPEG("-i " + Strings.Chr(34) + this_filename + Strings.Chr(34) + " -b:a 16k -y " + destination_file, ref output, ref out_error);
                        try
                        {
                            System.IO.File.Delete(HttpContext.Current.Server.MapPath("/audio/" + drv.appname.ToString() + "/" + call_date + "/" + session_id + file_ending));
                        }
                        catch (Exception ex)
                        {
                        }
                        file_ending = ".mp3";
                    }
                    this_filename = "/audio/" + drv.appname.ToString() + "/" + call_date + "/" + session_id + file_ending;
                    if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(this_filename)))
                    {
                        //UpdateTable("update XCC_REPORT_NEW set audio_link = '" + this_filename + "' where ID = " + Id);
                        var            isExist           = dataContext.XCC_REPORT_NEW.Where(x => x.ID == Id).FirstOrDefault();
                        XCC_REPORT_NEW tblXCC_REPORT_NEW = new XCC_REPORT_NEW();
                        if (isExist != null)
                        {
                            tblXCC_REPORT_NEW = dataContext.XCC_REPORT_NEW.Find(Id);
                            dataContext.Entry(tblXCC_REPORT_NEW).State = EntityState.Modified;
                            tblXCC_REPORT_NEW.bad_call_accepted        = System.DateTime.Now;
                            tblXCC_REPORT_NEW.audio_link = this_filename;
                            int result = dataContext.SaveChanges();
                        }
                        return(this_filename);
                    }
                    else
                    {
                        return(drv.audio_link.ToString());// already an mp3, file exists though doesn't match session ID
                    }
                }
                return("");
            }
        }
Ejemplo n.º 10
0
 public void end()
 {
     _client.Disconnect();
 }
Ejemplo n.º 11
0
 public override void Disconnect()
 {
     _client.Disconnect();
     OnPropertyChanged("IsConnected");
 }
Ejemplo n.º 12
0
 public void Init()
 {
     _client?.Disconnect();
     _client?.Dispose();
     _client = new Renci.SshNet.SftpClient(_host, _port, _userName == "" ? "anonymous" : _userName, _password);
 }
Ejemplo n.º 13
0
        static public void ImportProducts(string market)
        {
            sqlRequest sql = new sqlRequest();

            string path      = ConfigurationManager.AppSettings["ProductSource_Path"].ToString() + market + @"\";
            string imagePath = ConfigurationManager.AppSettings["ImageTemp_Path"].ToString() + market + @"\";

            string[] columnToIgnore = ConfigurationManager.AppSettings["Ignore_Column"].ToString().Trim().Split(';');

            string table_name = "products_" + market;

            sql.RequestText("TRUNCATE TABLE " + table_name + "_temp");

            //-Lire le fichier Excel
            string[] files = Directory.GetFiles(path);
            foreach (string file in files)
            {
                ManageError.Gestion_Log("Charge file : " + file, null, ManageError.Niveau.Info);

                FileInfo  fInfo = new FileInfo(file);
                DataTable tmp_table_structure = sql.RequestSelect("SELECT * FROM " + table_name + "_temp LIMIT 0");

                if (fInfo.Extension == ".xlsx" || fInfo.Extension == ".xls")
                {
                    using (Excel excel = new Excel(fInfo.FullName))
                    {
                        Dictionary <String, bool> urlsTraites = new Dictionary <string, bool>();

                        //Chercher tous les entetes
                        String colName = String.Empty;

                        //Verification des noms de champs
                        int           colCount = excel.ColumnCount();
                        List <string> columns  = new List <string>();

                        for (int colIndex = 0; colIndex < colCount; ++colIndex)
                        {
                            colName = excel.Cell(colIndex, 0).Trim();
                            if (colName.Length > 0)
                            {
                                bool find = false;
                                //Verifier le champs,//-La table peut contenir des champs dont le fichier ne dispose pas, mais pas l'inverse
                                foreach (DataColumn tableColNameColumn in tmp_table_structure.Columns)
                                {
                                    if (tableColNameColumn.ColumnName.ToString().ToUpper() == colName.ToUpper())
                                    {
                                        find = true;
                                        break;
                                    }
                                }
                                if (find == true)
                                {
                                    columns.Add(colName);
                                }
                                else
                                {
                                    //Rejeter une exception si on trouve une colonne qui n'existe pas dans la structure de la table + ne peut pas ignoré
                                    if (columnToIgnore.Contains(colName) == false)
                                    {
                                        string errorInfo = "Impossible de trouver la colonne <" + colName + "> dans la table " + table_name + "_temp, Modifer la strucuture de cette table.";
                                        ManageError.Gestion_Log(errorInfo, null, ManageError.Niveau.Info);
                                        throw new Exception(errorInfo);
                                    }
                                }
                            }
                        }


                        //-Inserer dans la table temporaire
                        int row_count = excel.RowCount();
                        for (int row_index = 1; row_index < row_count; ++row_index)
                        {
                            DataRow tmp_table_row = tmp_table_structure.NewRow();
                            for (int col_index = 0; col_index < colCount; ++col_index)
                            {
                                string excel_col_name = excel.Cell(col_index, 0);
                                if (columnToIgnore.Contains(excel_col_name))
                                {
                                    continue;
                                }

                                string col_str = columns[col_index];
                                tmp_table_row[col_str] = excel.Cell(col_index, row_index).Trim();
                            }

                            string url = tmp_table_row["URL"].ToString();
                            if (urlsTraites.ContainsKey(url) == false)
                            {
                                tmp_table_structure.Rows.Add(tmp_table_row);
                                urlsTraites[url] = true;
                            }
                        }

                        //Inserer dans la table temporaire
                        sql.BuldInsert(tmp_table_structure, table_name + "_temp");
                        ManageError.Gestion_Log("Insert " + tmp_table_structure.Rows.Count + " into " + table_name + "_temp", null, ManageError.Niveau.Info);


                        //-Calculer les keywods*/
                        JArray kw = RefreshKeywordsTree();
                        RefreshProductKeywords(kw, table_name + "_temp");
                        ManageError.Gestion_Log("Refresh keywords for " + table_name + "_temp", null, ManageError.Niveau.Info);


                        //Traiter la table temporaire pour inserer dans la table principale
                        sql.StoredProcedure(market + "_HandleTempTable", new List <MySqlParameter>(), 0);
                        ManageError.Gestion_Log("Handle tmp table", null, ManageError.Niveau.Info);

                        //-Calculer les caracteres pour les inserer dans la table des caracteres
                        ProductCaractere pc = new ProductCaractere();
                        pc.Interpret(market, table_name + "_temp", sql);
                        ManageError.Gestion_Log("Build caracteres list", null, ManageError.Niveau.Info);

                        //-Telecharger + Upload images

                        DataTable products2download = sql.RequestSelect("SELECT * FROM " + table_name + "_temp", 0);
                        using (WebClient client = new WebClient())
                        {
                            Regex regex = new Regex(@"https?://[^/\s]+/\S+\.(jpg|png|gif)");

                            String login    = System.Configuration.ConfigurationManager.AppSettings["sftp_login"].ToString();
                            String password = System.Configuration.ConfigurationManager.AppSettings["sftp_password"].ToString();
                            String adresse  = System.Configuration.ConfigurationManager.AppSettings["sftp_adresse"].ToString();

                            int    port     = System.Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["sftp_port"].ToString());
                            string basePath = System.Configuration.ConfigurationManager.AppSettings["sftp_basepath"].ToString();

                            Renci.SshNet.SftpClient oSFTP = new Renci.SshNet.SftpClient(adresse, port, login, password);
                            oSFTP.Connect();

                            foreach (DataRow product_row in products2download.Rows)
                            {
                                //Creer le dossier
                                string directory_path = imagePath + product_row["Id"].ToString() + @"\";
                                if (Directory.Exists(imagePath + product_row["Id"].ToString()) == false)
                                {
                                    Directory.CreateDirectory(directory_path);
                                }
                                string remoteDir = basePath + "img/" + market + "/" + product_row["Id"].ToString() + "/";
                                if (oSFTP.Exists(remoteDir) == false)
                                {
                                    oSFTP.CreateDirectory(remoteDir);
                                }
                                Dictionary <string, string> finished_images = new Dictionary <string, string>();
                                String urls  = product_row["images"].ToString();
                                Match  match = regex.Match(urls);
                                // int imgCount = 0;

                                while (match.Success)
                                {
                                    /*if (imgCount > 0) {
                                     *  break;
                                     * }*/

                                    String imgUrl = match.Value;


                                    if (finished_images.Keys.Contains(imgUrl) == false && imgUrl.Contains("50x50.jpg") == false)
                                    {
                                        Uri    uri      = new Uri(imgUrl);
                                        string filename = (finished_images.Count + 1) + Path.GetExtension(uri.LocalPath);
                                        try
                                        {
                                            /*client.DownloadFile(new Uri(imgUrl), directory_path + filename);
                                             * if (File.Exists(directory_path + filename))
                                             * {
                                             *  FileStream fs = new FileStream(directory_path + filename, FileMode.Open);
                                             *  oSFTP.UploadFile(fs, remoteDir + filename, true);
                                             *  fs.Close();
                                             */
                                            finished_images[imgUrl] = "";//(remoteDir + filename);

                                            /*    File.Delete(directory_path + filename);
                                             *  imgCount++;
                                             * }*/
                                        }
                                        catch (Exception e)
                                        {
                                            ManageError.Gestion_Log("Cannot download image : " + e.Message, null, ManageError.Niveau.Info);
                                        }
                                    }


                                    match = match.NextMatch();
                                }

                                JObject imgObjet = new JObject();
                                foreach (string imageurl in finished_images.Keys)
                                {
                                    imgObjet[imageurl] = finished_images[imageurl];
                                }
                                sql.RequestSelect("UPDATE " + table_name + " SET images = @img_json Where Id = @id", new List <MySqlParameter>()
                                {
                                    new MySqlParameter("@img_json", WebUtility.HtmlEncode(imgObjet.ToString())),
                                    new MySqlParameter("@id", product_row["Id"].ToString())
                                });

                                Directory.Delete(directory_path);
                            }

                            oSFTP.Disconnect();
                        }
                    }
                }

                fInfo.Delete();
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
            }
        }
Ejemplo n.º 14
0
 public void Disconnect()
 {
     _internalClient.Disconnect();
 }