public JsonResult Connect(int selectHostId) { var result = new JsonResponse(); HostDetailModel hostDetail = null; try { var hosts = (HostListModel)Session[Constants.SESSION_HOST_SETTING]; if (hosts == null) { hosts = HostAdmin.GetHostList(ConfigurationManager.AppSettings["HostList"]); } if (!HostAdmin.IsExistHostID(hosts.HostList, selectHostId)) { result.AddErrorInfo("errorMessage", "接続先のホスト情報が存在しません!"); } else { foreach (HostDetailModel host in hosts.HostList) { if (host.HostID == selectHostId) { hostDetail = new HostDetailModel(host); break; } } if (hostDetail != null && FTPControl.IsRemoteConnected(hostDetail)) { Session[Constants.SESSION_LOCAL_PATH] = hostDetail.LocalServerPath != "" && hostDetail.LocalServerPath != null ? hostDetail.LocalServerPath : "C:\\forwork\\localFolder"; Session[Constants.SESSION_REMOTE_PATH] = hostDetail.HostAddress; List <ResourceInfoModel> localResourceList = FTPControl.GetLocalResourceList((string)Session[Constants.SESSION_LOCAL_PATH]); List <ResourceInfoModel> remoteResourceList = FTPControl.GetRemoteResourceList(hostDetail.HostAddress, hostDetail, true); Session[Constants.SESSION_LOCAL_FILE_LIST] = localResourceList; Session[Constants.SESSION_REMOTE_FILE_LIST] = remoteResourceList; Session[Constants.SESSION_HOST_DETAIL] = hostDetail; string log = (string)Session[Constants.SESSION_OLD_LOG] + "ホスト" + hostDetail.HostAddress + "に接続しました。\r\n"; Session[Constants.SESSION_LOG] = log; Session[Constants.SESSION_OLD_LOG] = log; result.SetResult(true); } else { result.AddErrorInfo("errorMessage", "FTP接続に失敗しました。"); } } } catch (Exception) { result.AddErrorInfo("errorMessage", "接続時にエラーが発生しました。"); } return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet)); }
public ActionResult ViewServerInfo(string path, string env = "", string filterPattern = "") { var result = new JsonResponse(); var model = new FTPControlModel(); HostDetailModel hostDetail = (HostDetailModel)Session[Constants.SESSION_HOST_DETAIL]; string sessionLocalPath = (string)Session[Constants.SESSION_LOCAL_PATH]; string sessionRemotePath = (string)Session[Constants.SESSION_REMOTE_PATH]; string viewName = string.Empty; try { string localPath = string.Empty; string remotePath = string.Empty; List <ResourceInfoModel> localResourceList = new List <ResourceInfoModel>(); List <ResourceInfoModel> remoteResourceList = new List <ResourceInfoModel>(); if (env == Constants.ENV_LOCAL) { viewName = "_LocalServer"; // 一つ前のディレクトリに戻る場合 if (path.Equals("..")) { localPath = sessionLocalPath.Substring(0, sessionLocalPath.LastIndexOf("\\")); // ex)c:\\などのドライブまで上がった場合は最後に\\を付ける if (localPath.IndexOf("\\") == -1) { localPath = localPath + "\\"; } } else if (path.Equals("*")) { // リフレッシュ、フィルターをリセットする場合 localPath = sessionLocalPath; } else { localPath = path; } localResourceList = FTPControl.GetLocalResourceList(localPath); if (filterPattern != string.Empty) { localResourceList = FTPControl.GetFilteredList(localResourceList, filterPattern); model.LocalFilterPattern = filterPattern; } remotePath = (string)Session[Constants.SESSION_REMOTE_PATH]; remoteResourceList = (List <ResourceInfoModel>)Session[Constants.SESSION_REMOTE_FILE_LIST]; } else if (env == Constants.ENV_REMOTE) { viewName = "_RemoteServer"; // 一つ前のディレクトリに戻る場合 if (path.Equals("..")) { if (sessionRemotePath.IndexOf("/") != -1) { remotePath = sessionRemotePath.Substring(0, sessionRemotePath.LastIndexOf("/")); } else { remotePath = sessionRemotePath; } } else if (path.Equals("*")) { // リフレッシュ、フィルターをリセットする場合 remotePath = sessionRemotePath; } else { remotePath = path; } remoteResourceList = FTPControl.GetRemoteResourceList(remotePath, hostDetail, true); if (filterPattern != string.Empty) { remoteResourceList = FTPControl.GetFilteredList(remoteResourceList, filterPattern); model.RemoteFilterPattern = filterPattern; } localPath = (string)Session[Constants.SESSION_LOCAL_PATH]; localResourceList = (List <ResourceInfoModel>)Session[Constants.SESSION_LOCAL_FILE_LIST]; } else if (env == string.Empty && path.Equals("*")) { // ローカル&リモート両方とも初期化状態に戻す viewName = "_Server"; localPath = sessionLocalPath; remotePath = sessionRemotePath; localResourceList = FTPControl.GetLocalResourceList(localPath); remoteResourceList = FTPControl.GetRemoteResourceList(remotePath, hostDetail, true); } model.LocalList = localResourceList; model.LocalServerPath = localPath; model.RemoteList = remoteResourceList; model.RemoteServerPath = remotePath; Session[Constants.SESSION_LOCAL_PATH] = localPath; Session[Constants.SESSION_LOCAL_FILE_LIST] = localResourceList; Session[Constants.SESSION_REMOTE_PATH] = remotePath; Session[Constants.SESSION_REMOTE_FILE_LIST] = remoteResourceList; } catch (Exception e) { Session[Constants.SESSION_LOG] = string.Format("[Exception] {0},\r\n{1}", e.Message, e.StackTrace) + "\r\n"; } return(PartialView(viewName, model)); }