public static List <string> GetArchiveFilesListForLocalNetwork(AppSettings appSettings, int datasetId) { List <string> ArchiveFileNames = new List <string>(); ArchiveFileNames = ImpersonationHelper.LocalNetworkFiles(appSettings.Archival_Location["Username"], appSettings.Archival_Location["Password"], @"//" + appSettings.Archival_Location["Hostname"] + "/" + appSettings.Archival_Location["DefaultLocation"] + "/" + datasetId); return(ArchiveFileNames); }
//loading LocalNetwork Directories recursively private static List <TreeViewModel> GetLocalNetworkDirectorties(string username, string password, string folderPath) { List <TreeViewModel> newList = new List <TreeViewModel>(); try { List <string> newFolderList = ImpersonationHelper.Impersonate(username, password, folderPath); if (newFolderList != null && newFolderList.Count > 0) { foreach (string dir in newFolderList) { TreeViewModel obj = new TreeViewModel(); //push folder into final list obj.Value = dir.Substring(dir.LastIndexOf("\\") + 1); obj.Children = GetLocalNetworkDirectorties(username, password, dir); newList.Add(obj); } } } catch (Exception e) { throw; } return(newList); }
public static List <TreeViewModel> LoadLocalNetworkFolders(string host, string username, string password) { List <TreeViewModel> finalObjList = new List <TreeViewModel>(); try { List <string> directories = ImpersonationHelper.Impersonate(username, password, @"\\" + host); if (directories != null && directories.Count > 0) { foreach (string dir in directories) { TreeViewModel obj = new TreeViewModel(); //push folder into final list obj.Value = dir.Substring(dir.LastIndexOf("\\") + 1); obj.Children = GetLocalNetworkDirectorties(username, password, dir); finalObjList.Add(obj); } } } catch (Exception e) { return(null); } return(finalObjList); }
public static bool TestLocalNetworkConnection(string host, string username, string password) { try { ImpersonationHelper.Impersonate(username, password, @"\\" + host); } catch (Exception e) { return(false); } return(true); }
public static int CheckFileExistsLOCALNETWORK(string fileName, string location, string extension, string host, string username, string password) { int Count = 0; var path = GetFileNameAndExt(fileName).FirstOrDefault(); var ext = path.Key; var fn = path.Value; try { if (string.IsNullOrEmpty(ext)) { ext = GetFileExtensions().FirstOrDefault(f => f.Key == extension).Value; } var files = ImpersonationHelper.checkLocalNetworkFile(username, password, @"\\" + host + location); Count = files.Where(x => x.Contains(fn) && ext.ToLower() == Path.GetExtension(x).ToLower()).Count(); return(Count); } catch (Exception ex) { return(0); } }
public static int CopyArchiveFiles(AppSettings appSettings, string HostName, int Port, string UserName, string Password, string PrivateKey, string TargetLocation, OutboundFileResendViewModel outboundFileResendViewModel, string interfaceType) { List <string> failedFiles = new List <string>(); OutboundFileResendAudit record = new OutboundFileResendAudit(); List <OutboundFileResendAudit> outboundFileDALData = new List <OutboundFileResendAudit>(); try { foreach (string filename in outboundFileResendViewModel.resendSelectedArchiveFiles) { try { byte[] bytes = null; string defaulSftpArchiveLoction = appSettings.Archival_Location["DefaultLocation"] + "/" + outboundFileResendViewModel.datasetId; string Loactiontype = appSettings.Archival_Location["Location"]; if (Loactiontype == "SFTP") { bytes = ReadFileFromSFTP(appSettings, defaulSftpArchiveLoction + "/" + filename); } else if (Loactiontype == "FTP") { bytes = ReadFileFromFTP(appSettings, defaulSftpArchiveLoction + "/" + filename); } else if (Loactiontype == "LOCAL NETWORK") { bytes = ImpersonationHelper.ReadLocalNetworkFile(appSettings.Archival_Location["Username"], appSettings.Archival_Location["Password"], @"//" + appSettings.Archival_Location["Hostname"] + defaulSftpArchiveLoction + "/" + filename); } bool fileCopied = false; if (bytes != null) { if (interfaceType == "SFTP") { fileCopied = WriteFileToSFTP(HostName, Port, UserName, Cryptography.Decrypt(Password, PrivateKey), TargetLocation + "/" + filename, bytes); } else if (interfaceType == "FTP") { fileCopied = WriteFileToFTP(HostName, Port, UserName, Cryptography.Decrypt(Password, PrivateKey), TargetLocation + "/" + filename, bytes); } else if (interfaceType == "LOCAL NETWORK") { fileCopied = ImpersonationHelper.WriteLocalNetworkFile(UserName, Cryptography.Decrypt(Password, PrivateKey), @"//" + HostName + TargetLocation + "/" + filename, bytes); } } if (fileCopied) { record = SaveOutboundFileResendDetailsInDB(outboundFileResendViewModel, filename, defaulSftpArchiveLoction, TargetLocation); outboundFileDALData.Add(record); } else { failedFiles.Add(filename); } } catch (Exception) { //for failed files failedFiles.Add(filename); } } if (outboundFileDALData.Count > 0) { _outgestionFileResendDAL.CreateOutboundResendAudit(outboundFileDALData); } } catch (Exception e) { } return(failedFiles.Count);; }