public void Upload(Stream inStream, Stream outStream, string fileName) { _client.Connect(); if (_client.IsConnected) { _client.BufferSize = 4 * 1024;// bypass Payload error large files _client.UploadFile(inStream, fileName); if (_client.Exists(fileName)) { var confirmation = new Confirmation { HostName = _client.ConnectionInfo.Host, FileName = fileName, FileSize = _client.GetAttributes(fileName).Size }; var outJson = JToken.FromObject(confirmation).ToString(); using (var b = new StreamWriter(outStream, Encoding.UTF8, 1000, true)) { b.Write(outJson); b.Flush(); } } } else { throw new IOException($"Cannot connect to {_client.ConnectionInfo.Host}"); } }
public async Task <bool> DeleteFileFromFTPServer(string imageLocation) { //BitmapEncoder encoder = new TiffBitmapEncoder(); // byte[] biteArray = ImageSourceToBytes(encoder, QuestionImage); var taskResult = await Task.Run(() => { using (var client = new Renci.SshNet.SftpClient(Host, Port, Username, Password)) { client.Connect(); if (client.IsConnected) { client.ChangeDirectory(SFTPWorkingDirectory); //using (var ms = new MemoryStream(biteArray)) // { //client.BufferSize = (uint)ms.Length; // bypass Payload error large files if (client.Exists(client.WorkingDirectory + "/" + imageLocation)) { client.DeleteFile(client.WorkingDirectory + "/" + imageLocation); } // } return(true); } else { OutputMessage = "Couldn't connect to SFTP server"; return(false); } } }); return(taskResult); }
public BitmapImage DownloadImageFromSFTP(BitmapImage bitmapImage, string imageLocation) { using (var client = new Renci.SshNet.SftpClient(Host, Port, Username, Password)) { client.Connect(); if (client.IsConnected) { client.ChangeDirectory(SFTPWorkingDirectory); using (MemoryStream fileStream = new MemoryStream()) { client.DownloadFile(client.WorkingDirectory + "/" + imageLocation, fileStream); bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = fileStream; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); return(bitmapImage); } } else { OutputMessage = "Couldn't connect to SFTP server."; return(null); } } }
public bool SaveImageToFTPServer(ImageSource imageSource, string imageLocationMemory, string imageLocationDisk) { BitmapEncoder encoder = new TiffBitmapEncoder(); byte[] biteArray = ImageSourceToBytes(encoder, imageSource); // Function returns byte[] csv file using (var client = new Renci.SshNet.SftpClient(Host, Port, Username, Password)) { client.Connect(); if (client.IsConnected) { client.ChangeDirectory(SFTPWorkingDirectory); using (var ms = new MemoryStream(biteArray)) { client.BufferSize = (uint)ms.Length; // bypass Payload error large files client.UploadFile(ms, imageLocationDisk); // imageLocationDisk == openFileDialog.FileName client.RenameFile(client.WorkingDirectory + "/" + imageLocationDisk, client.WorkingDirectory + "/" + imageLocationMemory); return(true); } } else { OutputMessage = "Couldn't connect to SFTP server."; return(false); } } }
public async Task <bool> WriteImageSourceAsByteArraySFTP(ImageSource imageSource, string imageLocationMemory) { var taskResult = await Task.Run(() => { BitmapEncoder encoder = new TiffBitmapEncoder(); byte[] biteArray = ImageSourceToBytes(encoder, imageSource); // Function returns byte[] csv file using (var client = new Renci.SshNet.SftpClient(Host, Port, Username, Password)) { client.Connect(); if (client.IsConnected) { client.ChangeDirectory(SFTPWorkingDirectory); using (var ms = new MemoryStream(biteArray)) { client.BufferSize = (uint)ms.Length; // bypass Payload error large files client.Create(SFTPWorkingDirectory + "/" + imageLocationMemory); client.WriteAllBytes(SFTPWorkingDirectory + "/" + imageLocationMemory, biteArray); // imageLocationDisk == openFileDialog.FileName return(true); } } else { OutputMessage = "Couldn't connect to SFTP server."; return(false); } } }); return(taskResult); }
/// <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); }
static void Main(string[] args) { Network.SelectNetwork(); DataManager.IsServerConnected(); List <MoveConfig> MoveConfigs = MoveConfig.MoveConfigs(); foreach (MoveConfig MoveConfig in MoveConfigs) { //PrePostProcess.Call(MoveConfig.DirPostProcessExe); //Using Open Source Nuget Package SSH.NET by Renci using (var sftp = new Renci.SshNet.SftpClient(SFTP.host, SFTP.user, SFTP.pass)) { sftp.Connect(); var files = sftp.ListDirectory(MoveConfig.DirSFTP); foreach (var file in files) { string remoteFileName = file.Name; if (!file.Name.StartsWith(".") && (file.LastWriteTime.Date == DateTime.Today)) { using (Stream file1 = File.OpenWrite(MoveConfig.DirSFTP + remoteFileName)) { //sftp.DownloadFile(remoteDir + remoteFileName, file1); break; } } } //foreach fileInSFTP } //using } //foreach moveConfig } //Main()
//private const string FTP_SERVER = "210.177.12.144"; //private const string FTP_USR_ID = "sfhpmprd01"; //private const string FTP_USR_PW = "M8x72bpaT"; public static bool FileUploadSFTP(string fileName) { try { using (var client = new Renci.SshNet.SftpClient(FTP_SERVER, 22, FTP_USR_ID, FTP_USR_PW)) { client.Connect(); if (client.IsConnected) { using (var fileStream = new FileStream(Path.Combine(Path.GetTempPath(), fileName), FileMode.Open)) { client.BufferSize = 4 * 1024; // bypass Payload error large files client.UploadFile(fileStream, fileName); AuditLog.Log("BlueX File is uploaded to FTP successfully. [" + fileName + "]"); } } } return(true); } catch (Exception e) { AuditLog.Log("Exception Line 109 " + e.Message); return(false); } }
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); }
public async Task <byte[]> ReadByteArrayFromSFTP(string imageLocationMemory) { var taskResult = await Task.Run(() => { using (var client = new Renci.SshNet.SftpClient(Host, Port, Username, Password)) { client.Connect(); if (client.IsConnected) { client.ChangeDirectory(SFTPWorkingDirectory); if (client.Exists(client.WorkingDirectory + "/" + imageLocationMemory)) { return(client.ReadAllBytes(client.WorkingDirectory + "/" + imageLocationMemory));// imageLocationDisk == openFileDialog.FileName } else { return(null); } } else { OutputMessage = "Couldn't connect to SFTP server."; return(null); } } }); return(taskResult); }
public IDirectory GetDirectoy(string path) { var client = new Renci.SshNet.SftpClient(this.Host, this.Port, this.UserName, this.Password); client.Connect(); var name = path.Split(new string[]{@"\",@"/"}, StringSplitOptions.RemoveEmptyEntries).Last(); return new Directory(path, client, name); }
public IDirectory GetDirectoy(string path) { var client = new Renci.SshNet.SftpClient(this.Host, this.Port, this.UserName, this.Password); client.Connect(); var name = path.Split(new string[] { @"\", @"/" }, StringSplitOptions.RemoveEmptyEntries).Last(); return(new Directory(path, client, name)); }
public IDirectory GetRootDirectory() { var client = new Renci.SshNet.SftpClient(this.Host, this.Port, this.UserName, this.Password); client.Connect(); var dir = client.ListDirectory(this.RepositoryPath); var dir2 = client.ListDirectory("/PackageRepository/Core/0.0.1.193"); //var sftp = new Sftp(); return new Directory(this.RepositoryPath, client, ""); }
public IDirectory GetRootDirectory() { var client = new Renci.SshNet.SftpClient(this.Host, this.Port, this.UserName, this.Password); client.Connect(); var dir = client.ListDirectory(this.RepositoryPath); var dir2 = client.ListDirectory("/PackageRepository/Core/0.0.1.193"); //var sftp = new Sftp(); return(new Directory(this.RepositoryPath, client, "")); }
public void Login(string host) { if (isLoggedIn) { return; } client = new Renci.SshNet.SftpClient(host, port, username, password); client.Connect(); isLoggedIn = true; }
// 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(); } }
public bool Connect() { try { _sftpClient.Connect(); return(true); } catch (Exception) { return(false); } }
public void connect() { try { if (_client.IsConnected == false) { _client.Connect(); } } catch (Exception ex) { throw new Exception("Cannot connect to the host. " + ex.Message, ex); } }
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); }
public bool Upload(FileInfo localFile, string remoteFileName) { if (!localFile.Exists) { throw new Exception(string.Format("The local file does not exist, the file path: {0}", localFile.FullName)); } using (var inputStream = localFile.OpenRead()) using (var client = new Renci.SshNet.SftpClient(_host, _username, _password)) { client.Connect(); client.UploadFile(inputStream, remoteFileName); } return(true); }
private static void OpenSftpConnection() { try { Utils.CLogger.WriteLog("Opening SFTP CONNECTION START"); connectioninfo = new Renci.SshNet.ConnectionInfo(SFTP_HOST, SFTP_USER, new Renci.SshNet.PasswordAuthenticationMethod(SFTP_USER, SFTP_PWD), new Renci.SshNet.PrivateKeyAuthenticationMethod("rsa.key")); SFTPClient = new Renci.SshNet.SftpClient(connectioninfo); SFTPClient.Connect(); Utils.CLogger.WriteLog("SFTP CONNECTION Opened with HOST " + SFTP_HOST); Utils.CLogger.WriteLog("Waiting for commands "); } catch (Exception ex) { Utils.CLogger.WriteLog(ex); } }
private void SendFIleOverSFTP() { Renci.SshNet.SftpClient sftp = new Renci.SshNet.SftpClient("119.23.71.29", "root", "Zyp885299"); sftp.Connect(); FileInfo fi = new FileInfo(@"/Users/luweiping/Downloads/nginx-1.12.0-1.el7.ngx.x86_64.rpm"); var allLength = fi.Length; sftp.UploadFile(new System.IO.FileStream(fi.FullName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite), "/home/parallels/Downloads/nginx-1.12.0-1.el7.ngx.x86_64.rpm", (pro) => { Console.WriteLine((pro * 1.0d / allLength * 1.0d).ToString("P")); }); Console.WriteLine("finished."); while (true) { System.Threading.Thread.Sleep(500); } }
public static bool CheckFileExistsOnFTP(string fileName) { try { string logMessage = ""; long ftp_fileLen = 0; using (var sftp = new Renci.SshNet.SftpClient(FTP_SERVER, 22, FTP_USR_ID, FTP_USR_PW)) { try { sftp.Connect(); SftpFile file = sftp.Get(fileName); ftp_fileLen = file.Attributes.Size; } catch (Exception Sftpex) { AuditLog.Log("Exception Line 129 " + Sftpex.ToString()); } } long fileLen = new System.IO.FileInfo(Path.Combine(Path.GetTempPath(), fileName)).Length; logMessage = "BlueX File is existed to FTP? "; if (ftp_fileLen == fileLen) { logMessage += "[Yes]"; } else { logMessage += "[No]"; } AuditLog.Log(logMessage); return(true); } catch (WebException ex) { AuditLog.Log("Exception Line 148 " + ex.Message); FtpWebResponse response = (FtpWebResponse)ex.Response; if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable) { return(false); } } return(false); }
static void Main(string[] args) { Console.WriteLine("Client started"); var sftpClient = new Renci.SshNet.SftpClient("localhost", 2228, "foo", "pass"); var sourceRoot = "files/"; sftpClient.Connect(); var files = new string[] { "20MB.zip", "50MB.zip" }; var runs = 20; for (var i = 0; i < runs; i++) { Console.WriteLine("Run: " + (i + 1)); foreach (var file in files) { var source = sourceRoot + file; Console.WriteLine("Source: " + source); var dest = "/upload/" + file; Console.WriteLine("Destination: " + dest); using (var stream = File.Open(source, FileMode.Open)) { sftpClient.UploadFile(stream, dest, value => { Console.Write("*"); }); } Console.WriteLine(); } } }
public string SendIt() { var host = ConfigurationManager.AppSettings["Host"]; var zipFile = Factory.GetZipFile(); Renci.SshNet.SftpClient sftpClient = new Renci.SshNet .SftpClient(host, ConfigurationManager.AppSettings["FtpUserName"], ConfigurationManager.AppSettings["FtpUserPass"]); sftpClient.Connect(); sftpClient .ChangeDirectory(ConfigurationManager.AppSettings["WorkingDirectory"]); using (var fileStream = new FileStream(zipFile, FileMode.Open)) { sftpClient.BufferSize = 4 * 1024; // bypass Payload error large files sftpClient.UploadFile(fileStream, Path.GetFileName(zipFile)); } return(new WebClient() .DownloadString(ConfigurationManager.AppSettings["UpdateDatabaseUrl"])); }
/// <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(""); } }
public void Connect() { _internalClient.Connect(); }
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); } } }
public override void Connect() { _client.Connect(); OnPropertyChanged("IsConnected"); }