예제 #1
0
        public void OnStoreFile(object sender, FileSysEntry_EventArgs e)
        {
            try
            {
                LogHelper.InfoLog(string.Format("OnStoreFile, e.Name = {0}", e.Name));

                if (!File.Exists(GetPhysicalPath(e.Name)))
                {
                    e.FileStream = File.Create(GetPhysicalPath(e.Name));
                }
                else
                {
                    try
                    {
                        File.Delete(GetPhysicalPath(e.Name));
                    }
                    catch (System.Exception ex)
                    {
                        LogHelper.ErrorLog(ex);
                    }

                    e.FileStream = File.Create(GetPhysicalPath(e.Name));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog(ex);
                e.Validated = false;
            }
        }
예제 #2
0
 public void OnDirExists(object sender, FileSysEntry_EventArgs e)
 {
     if (!Directory.Exists(GetPhysicalPath(e.Name)))
     {
         e.Validated = false;
     }
 }
예제 #3
0
 public void OnDeleteFile(object sender, FileSysEntry_EventArgs e)
 {
     if (File.Exists(GetPhysicalPath(e.Name)))
     {
         File.Delete(GetPhysicalPath(e.Name));
     }
     else
     {
         e.Validated = false;
     }
 }
예제 #4
0
 public void OnDeleteDir(object sender, FileSysEntry_EventArgs e)
 {
     if (!IsVirtualDir(e.Name) && Directory.Exists(GetPhysicalPath(e.Name)))
     {
         Directory.Delete(GetPhysicalPath(e.Name));
     }
     else
     {
         e.Validated = false;
     }
 }
예제 #5
0
 public void OnCreateDir(object sender, FileSysEntry_EventArgs e)
 {
     if (Directory.Exists(GetPhysicalPath(e.Name)))
     {
         e.Validated = false;
     }
     else
     {
         Directory.CreateDirectory(GetPhysicalPath(e.Name));
     }
 }
예제 #6
0
 public void OnFileExists(object sender, FileSysEntry_EventArgs e)
 {
     try
     {
         if (File.Exists(GetPhysicalPath(e.Name)))
         {
             e.Validated = true;
         }
     }
     catch
     {
         e.Validated = false;
     }
 }
예제 #7
0
        public void OnRenameDirFile(object sender, FileSysEntry_EventArgs e)
        {
            // Remove last /
            string to   = e.NewName.Substring(0, e.NewName.Length - 1);
            string from = e.Name.Substring(0, e.Name.Length - 1);

            if (IsVirtualDir(to) || IsVirtualDir(from) || Directory.Exists(GetPhysicalPath(to)) || File.Exists(GetPhysicalPath(to)))
            {
                e.Validated = false;
            }
            else
            {
                if (Directory.Exists(GetPhysicalPath(from)))
                {
                    Directory.Move(GetPhysicalPath(from), GetPhysicalPath(to));
                }
                else if (File.Exists(GetPhysicalPath(from)))
                {
                    File.Move(GetPhysicalPath(from), GetPhysicalPath(to));
                }
            }
        }
예제 #8
0
        public void OnGetFile(object sender, FileSysEntry_EventArgs e)
        {
            try
            {
                //if(File.Exists(GetPhysicalPath(e.Name))){
                //	e.FileStream = File.OpenRead(GetPhysicalPath(e.Name));
                OtherDirFileInfo ofi = new OtherDirFileInfo();

                string[] user = e.Session.UserName.Split('|');
                if (user.Length < 2)
                {
                    LogHelper.InfoLog(string.Format("User's format error,user:{0};", e.Session.UserName));
                    return;
                }
                ofi.UserName = user[0];
                ofi.TenantID = user[1];
                ofi.Password = e.Session.Password;

                string[] request_paths = e.Name.Split('-');
                if (request_paths.Length != 3)
                {
                    //LogHelper.InfoLog("Request file format error!");
                    return;
                }

                string refe_type = request_paths[0].Substring(request_paths[0].IndexOf('/') + 1);
                //按文件名请求绝对路径
                Parameters pars   = Parameters.Instance();
                string     result = Common.SendSSLMsg(pars.SftpParam.AuthenticateServerHost, pars.SftpParam.AuthenticateServerPort, CreateAuthMsg(ofi, refe_type, request_paths[1], request_paths[2]));
                string[]   strings;
                if (ReturnAuthAnalyze(result, out strings, false))
                {
                    if (strings.Length > 2)
                    {
                        string soucre_file_path = strings[1];//源文件绝对路径
                        try
                        {
                            if (File.Exists(soucre_file_path))
                            {
                                e.FileStream = File.OpenRead(soucre_file_path);
                            }
                            else
                            {
                                LogHelper.ErrorLog(string.Format("file not found,filename:{0}", soucre_file_path));
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelper.ErrorLog(ex.Message);
                        }
                    }
                    else
                    {
                        LogHelper.ErrorLog(string.Format("AuthAnalyze failed,count:{0}", strings.Length));
                    }
                }
                else
                {
                    LogHelper.ErrorLog(string.Format("Authenticate failed,reference type:{0},reference:{1},partition:{2}"
                                                     , refe_type, request_paths[1], request_paths[2]));
                }
            }
            catch
            {
                e.Validated = false;
            }
        }
예제 #9
0
        public void OnGetDirInfo(object sender, FileSysEntry_EventArgs e)
        {
            try
            {
                DataTable dt = e.DirInfo.Tables["DirInfo"];

                string physicalPath = GetPhysicalPath(e.Name);

                // Add directories
                if (Directory.Exists(physicalPath))
                {
                    string[] dirs = Directory.GetDirectories(physicalPath);
                    foreach (string d in dirs)
                    {
                        DataRow dr = dt.NewRow();
                        dr["Name"] = new DirectoryInfo(d).Name;
                        dr["Date"] = Directory.GetCreationTime(d);
                        //	dr["Size"] = "";
                        dr["IsDirectory"] = true;

                        dt.Rows.Add(dr);
                    }

                    // Add virtual folders
                    if (File.Exists(physicalPath + "__Config_ftp.xml"))
                    {
                        try
                        {
                            DataSet ds = new DataSet();
                            ds.ReadXml(physicalPath + "__Config_ftp.xml");

                            foreach (DataRow dr in ds.Tables["virtualFolder"].Rows)
                            {
                                // ToDo: if virtual folder is same name as physical folder

                                // Add vitual folder to list only if it exists
                                string vDirPhysicalPath = dr["path"].ToString();
                                if (Directory.Exists(vDirPhysicalPath))
                                {
                                    DataRow drX = dt.NewRow();
                                    drX["Name"] = dr["name"].ToString();
                                    drX["Date"] = Directory.GetCreationTime(vDirPhysicalPath);
                                    //	drX["Size"] = "";
                                    drX["IsDirectory"] = true;

                                    dt.Rows.Add(drX);
                                }
                            }
                        }
                        catch
                        {
                        }
                    }

                    // Add files
                    string[] files = Directory.GetFiles(physicalPath);
                    foreach (string f in files)
                    {
                        // Hide config file
                        if (Path.GetFileName(f).ToLower() != "__config_ftp.xml")
                        {
                            DataRow dr = dt.NewRow();
                            dr["Name"]        = Path.GetFileName(f);
                            dr["Date"]        = File.GetCreationTime(f);
                            dr["Size"]        = new FileInfo(f).Length;
                            dr["IsDirectory"] = false;

                            dt.Rows.Add(dr);
                        }
                    }
                }
            }
            catch
            {
                e.Validated = false;
            }
        }