FtpPublic.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:3k
源码类别:

网格计算

开发平台:

Visual C++

  1. #include "stdAfx.h"
  2. #include "FtpPublic.h"
  3. //get all ftp profile names list.
  4. BOOL GetAllFtpProfileNames(CStringList &oProfileNamesList)
  5. {
  6. CRegister regKey;
  7. //open ftp root key.
  8. if(!regKey.Open(HKEY_CURRENT_USER, REG_SFTPSEETINGKEY))
  9. {
  10. TRACE0("Failed to open the ftp registry root keyn");
  11. return FALSE;
  12. }
  13. return regKey.EnumSubKeyNames(oProfileNamesList);
  14. }
  15. //get the ftp setting from profile name.
  16. BOOL GetFtpSiteInfo(LPCSTR szProfileName, CFtpSite &oFtpSite)
  17. {
  18. CRegister regKey;
  19. //get the profile path in the registry.
  20. CString strkeypath;
  21. strkeypath.Format("%s\%s", REG_SFTPSEETINGKEY, szProfileName);
  22. //open ftp root key.
  23. if(!regKey.KeyExists(HKEY_CURRENT_USER, strkeypath.GetBuffer(0)))
  24. {
  25. TRACE0("Specialed ftp registry key doesn't existn");
  26. return FALSE;
  27. }
  28. if(!regKey.Open(HKEY_CURRENT_USER, strkeypath.GetBuffer(0)))
  29. {
  30. TRACE0("Failed to open the ftp someone profile registry keyn");
  31. return FALSE;
  32. }
  33. oFtpSite.m_bPASVMode = regKey.Read_Bool_Value(REG_BFTPPASVMODE);
  34. oFtpSite.m_bAnonymous = regKey.Read_Bool_Value(REG_BFTPANONYMOUS);
  35. oFtpSite.m_sProfile = szProfileName;
  36. oFtpSite.m_sHost = regKey.Read_String_Value(REG_SFTPHOSTNAME);
  37. oFtpSite.m_nPort = regKey.Read_DWord_Value(REG_SFTPPORT);
  38. oFtpSite.m_sUser = regKey.Read_String_Value(REG_SFTPUSERNAME);
  39. oFtpSite.m_sPassword = regKey.Read_String_Value(REG_SFTPPASSWORD);
  40. oFtpSite.m_sDowntoDir = regKey.Read_String_Value(REG_SFTPDOWNTODIR);
  41. oFtpSite.m_sDescription= regKey.Read_String_Value(REG_SFTPDESCRIPTION);
  42. return TRUE;
  43. }
  44. //add one ftp site setting into the registry.
  45. BOOL AddFtpSiteInfo(CFtpSite &oFtpSite)
  46. {
  47. CRegister regKey;
  48. //get the profile path in the registry.
  49. CString strkeypath;
  50. strkeypath.Format("%s\%s", REG_SFTPSEETINGKEY, oFtpSite.m_sProfile);
  51. //open | new ftp setting root key.
  52. if(!regKey.Open(HKEY_CURRENT_USER, strkeypath.GetBuffer(0)))
  53. {
  54. TRACE0("Failed to open the ftp someone profile registry keyn");
  55. return FALSE;
  56. }
  57. BOOL bret = regKey.Write_Bool_Value(REG_BFTPPASVMODE, oFtpSite.m_bPASVMode);
  58. bret = bret && regKey.Write_Bool_Value(REG_BFTPANONYMOUS, oFtpSite.m_bAnonymous);
  59. bret = bret && regKey.Write_String_Value(REG_SFTPHOSTNAME, oFtpSite.m_sHost);
  60. bret = bret && regKey.Write_DWord_Value(REG_SFTPPORT, oFtpSite.m_nPort);
  61. bret = bret && regKey.Write_String_Value(REG_SFTPUSERNAME, oFtpSite.m_sUser);
  62. bret = bret && regKey.Write_String_Value(REG_SFTPPASSWORD, oFtpSite.m_sPassword);
  63. bret = bret && regKey.Write_String_Value(REG_SFTPDOWNTODIR, oFtpSite.m_sDowntoDir);
  64. bret = bret && regKey.Write_String_Value(REG_SFTPDESCRIPTION, oFtpSite.m_sDescription);
  65. return bret;
  66. }
  67. //delete one existing ftp site setting from the registry.
  68. BOOL RemoveFtpSiteInfo(LPCSTR szProfileName)
  69. {
  70. CRegister regKey;
  71. //get the profile path in the registry.
  72. CString strkeypath;
  73. strkeypath.Format("%s\%s", REG_SFTPSEETINGKEY, szProfileName);
  74. //open ftp root key.
  75. if(!regKey.KeyExists(HKEY_CURRENT_USER, strkeypath.GetBuffer(0)))
  76. {
  77. TRACE0("Specialed ftp registry key doesn't existn");
  78. return FALSE;
  79. }
  80. //open ftp setting root key.
  81. if(!regKey.Open(HKEY_CURRENT_USER, REG_SFTPSEETINGKEY))
  82. {
  83. TRACE0("Failed to open the ftp someone profile registry keyn");
  84. return FALSE;
  85. }
  86. return regKey.DeleteSubKey(szProfileName);
  87. }