示例#1
0
        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));
        }
示例#2
0
        public JsonResult ConnectTest(HostDetailModel newHostDetail)
        {
            var result = new JsonResponse();

            try
            {
                if (FTPControl.IsRemoteConnected(newHostDetail))
                {
                    result.SetResult(true);
                }
                else
                {
                    result.AddErrorInfo("errorMessage", "接続テストに失敗しました!");
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "予期せぬエラー");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }