public async Task <ActionResult> Upload(IFormFile file, string RiskId, string documentName) { try { if (file.Length > 0) { string[] detectFileName = file.FileName.Split('\\'); //remove space on filename or special characters string fileNameOnly = detectFileName[detectFileName.Length - 1].Replace(" ", ""); string originalFileName = fileNameOnly; #region clear file name for any special characters fileNameOnly = fileNameOnly.Replace("'", ""); fileNameOnly = fileNameOnly.Replace("-", ""); fileNameOnly = fileNameOnly.Replace("_", ""); fileNameOnly = fileNameOnly.Replace("$", ""); fileNameOnly = fileNameOnly.Replace("%", ""); fileNameOnly = fileNameOnly.Replace("@", ""); fileNameOnly = fileNameOnly.Replace("*", ""); fileNameOnly = fileNameOnly.Replace("#", ""); #endregion Guid ramdomId = Guid.NewGuid(); fileNameOnly = RiskId + "_" + ramdomId + "_" + fileNameOnly; string remoteDirectory = "/document/" + fileNameOnly; using (FtpClient client = new FtpClient()) { client.Host = "fraweb.iweb-storage.com"; client.Port = 21; client.Credentials = new NetworkCredential("fraweb-admin", "P@$$word123"); client.UploadFile(file.FileName, remoteDirectory); client.RetryAttempts = 1; client.UploadFile(file.FileName, remoteDirectory, FtpExists.Overwrite, false, FtpVerify.Retry); client.Disconnect(); } Document fileDocument = new Document { RiskAssessmentID = RiskId, DocumentName = documentName, FileName = originalFileName, FTPLink = remoteDirectory, DocumentGUID = ramdomId.ToString() }; await _documentRepository.AddToDocumentAsync(fileDocument); } } catch (Exception exception) { return(Json(new { success = false, response = exception.Message })); } return(Ok()); }