FTP.CPP
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:9k
源码类别:

Delphi/CppBuilder

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "FTP.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TFormMain *FormMain;
  9. //---------------------------------------------------------------------------
  10. __fastcall TFormMain::TFormMain(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TFormMain::Button1Click(TObject *Sender)
  16. {
  17.   if (CheckBox1->Checked)
  18.   {
  19.     NMFTP1->Proxy = Edit6->Text;
  20.     NMFTP1->Proxy = StrToInt(Edit7->Text);
  21.   }
  22.   NMFTP1->Host = HostTxt->Text;
  23.   NMFTP1->Port = StrToInt(PortTxt->Text);
  24.   NMFTP1->UserID = UserTxt->Text;
  25.   NMFTP1->Password = PassTxt->Text;
  26.   NMFTP1->Connect();
  27.   if(NMFTP1->Connected==true)
  28.   {
  29.   TabSheet2->TabVisible=true;
  30.   TabSheet3->TabVisible=true;
  31.   }
  32. }
  33. //---------------------------------------------------------------------------
  34. void __fastcall TFormMain::Button2Click(TObject *Sender)
  35. {
  36.   NMFTP1->Disconnect();
  37. }
  38. //---------------------------------------------------------------------------
  39. void __fastcall TFormMain::Button3Click(TObject *Sender)
  40. {
  41.   NMFTP1->Nlist();
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TFormMain::Button4Click(TObject *Sender)
  45. {
  46.   NMFTP1->List();
  47. }
  48. //---------------------------------------------------------------------------
  49. void __fastcall TFormMain::Button5Click(TObject *Sender)
  50. {
  51.   NMFTP1->ChangeDir(DirTxt->Text);
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TFormMain::Button6Click(TObject *Sender)
  55. {
  56.   NMFTP1->Download(RemoteTxt->Text, LocalTxt->Text);
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TFormMain::Button7Click(TObject *Sender)
  60. {
  61.   NMFTP1->Abort();
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TFormMain::Button8Click(TObject *Sender)
  65. {
  66.   NMFTP1->DownloadRestore(RemoteTxt->Text, LocalTxt->Text);
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TFormMain::Button17Click(TObject *Sender)
  70. {
  71.   NMFTP1->Reinitialize();
  72.   PageControl1->ActivePage = TabSheet2;
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TFormMain::Button9Click(TObject *Sender)
  76. {
  77.   NMFTP1->Abort();
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TFormMain::NMFTP1Connect(TObject *Sender)
  81. {
  82.   StatusBar1->SimpleText = "Connected";
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TFormMain::NMFTP1ConnectionFailed(TObject *Sender)
  86. {
  87.   ShowMessage("Connection Failed");        
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TFormMain::NMFTP1Disconnect(TObject *Sender)
  91. {
  92.   if (StatusBar1 != 0)
  93.     StatusBar1->SimpleText = "Disconnected";        
  94. }
  95. //---------------------------------------------------------------------------
  96. void __fastcall TFormMain::NMFTP1Error(TComponent *Sender, WORD Errno,
  97.       AnsiString Errmsg)
  98. {
  99.   ShowMessage("Error "+IntToStr(Errno)+": "+Errmsg);        
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TFormMain::NMFTP1Failure(bool &handled, TCmdType Trans_Type)
  103. {
  104.   switch (Trans_Type) {
  105.     case cmdChangeDir: StatusBar1->SimpleText = "ChangeDir failure"; break;
  106.     case cmdMakeDir: StatusBar1->SimpleText = "MakeDir failure"; break;
  107.     case cmdDelete: StatusBar1->SimpleText = "Delete failure"; break;
  108.     case cmdRemoveDir: StatusBar1->SimpleText = "RemoveDir failure"; break;
  109.     case cmdList: StatusBar1->SimpleText = "List failure"; break;
  110.     case cmdRename: StatusBar1->SimpleText = "Rename failure"; break;
  111.     case cmdUpRestore: StatusBar1->SimpleText = "UploadRestore failure"; break;
  112.     case cmdDownRestore: StatusBar1->SimpleText = "DownloadRestore failure"; break;
  113.     case cmdDownload: StatusBar1->SimpleText = "Download failure"; break;
  114.     case cmdUpload: StatusBar1->SimpleText = "Upload failure"; break;
  115.     case cmdAppend: StatusBar1->SimpleText = "UploadAppend failure"; break;
  116.     case cmdReInit: StatusBar1->SimpleText = "ReInit failure"; break;
  117.     case cmdAllocate: StatusBar1->SimpleText = "Allocate failure"; break;
  118.     case cmdNList: StatusBar1->SimpleText = "NList failure"; break;
  119.     case cmdDoCommand: StatusBar1->SimpleText = "DoCommand failure"; break;
  120. default: ShowMessage("Unrecognized command failed."); break;
  121.   }
  122. }
  123. //---------------------------------------------------------------------------
  124. void __fastcall TFormMain::NMFTP1HostResolved(TComponent *Sender)
  125. {
  126.   StatusBar1->SimpleText = "Host Resolved";        
  127. }
  128. //---------------------------------------------------------------------------
  129. void __fastcall TFormMain::NMFTP1InvalidHost(bool &handled)
  130. {
  131.   AnsiString NewHost;
  132.   if (InputQuery("Invalid Host", "Please Choose another host", NewHost))
  133.   {
  134.     NMFTP1->Host = NewHost;
  135.     handled = true;
  136.   }
  137. }
  138. //---------------------------------------------------------------------------
  139. void __fastcall TFormMain::NMFTP1ListItem(AnsiString Listing)
  140. {
  141.   Memo1->Lines->Add(Listing);
  142. }
  143. //---------------------------------------------------------------------------
  144. void __fastcall TFormMain::NMFTP1PacketRecvd(TObject *Sender)
  145. {
  146.   StatusBar1->SimpleText = IntToStr(NMFTP1->BytesRecvd)+" bytes of "+IntToStr(NMFTP1->BytesTotal)+" received";
  147. }
  148. //---------------------------------------------------------------------------
  149. void __fastcall TFormMain::NMFTP1PacketSent(TObject *Sender)
  150. {
  151.   StatusBar1->SimpleText = IntToStr(NMFTP1->BytesSent)+" bytes of "+IntToStr(NMFTP1->BytesTotal)+" sent";        
  152. }
  153. //---------------------------------------------------------------------------
  154. void __fastcall TFormMain::NMFTP1Status(TComponent *Sender, AnsiString Status)
  155. {
  156.   if (StatusBar1 != 0)
  157.     StatusBar1->SimpleText = Status;        
  158. }
  159. //---------------------------------------------------------------------------
  160. void __fastcall TFormMain::NMFTP1Success(TCmdType Trans_Type)
  161. {
  162.   switch(Trans_Type)
  163.   {
  164.     case cmdChangeDir: StatusBar1->SimpleText = "ChangeDir success"; break;
  165.     case cmdMakeDir: StatusBar1->SimpleText = "MakeDir success"; break;
  166.     case cmdDelete: StatusBar1->SimpleText = "Delete success"; break;
  167.     case cmdRemoveDir: StatusBar1->SimpleText = "RemoveDir success"; break;
  168.     case cmdList: StatusBar1->SimpleText = "List success"; break;
  169.     case cmdRename: StatusBar1->SimpleText = "Rename success"; break;
  170.     case cmdUpRestore: StatusBar1->SimpleText = "UploadRestore success"; break;
  171.     case cmdDownRestore: StatusBar1->SimpleText = "DownloadRestore success"; break;
  172.     case cmdDownload: StatusBar1->SimpleText = "Download success"; break;
  173.     case cmdUpload: StatusBar1->SimpleText = "Upload success"; break;
  174.     case cmdAppend: StatusBar1->SimpleText = "UploadAppend success"; break;
  175.     case cmdReInit: StatusBar1->SimpleText = "ReInit success"; break;
  176.     case cmdAllocate: StatusBar1->SimpleText = "Allocate success"; break;
  177.     case cmdNList: StatusBar1->SimpleText = "NList success"; break;
  178.     case cmdDoCommand: StatusBar1->SimpleText = "DoCommand success"; break;
  179.   }
  180. }
  181. //---------------------------------------------------------------------------
  182. void __fastcall TFormMain::NMFTP1TransactionStart(TObject *Sender)
  183. {
  184.   StatusBar1->SimpleText = "Starting data transaction";        
  185. }
  186. //---------------------------------------------------------------------------
  187. void __fastcall TFormMain::NMFTP1TransactionStop(TObject *Sender)
  188. {
  189.   StatusBar1->SimpleText = "Transaction Complete";        
  190. }
  191. //---------------------------------------------------------------------------
  192. void __fastcall TFormMain::NMFTP1UnSupportedFunction(TCmdType Trans_Type)
  193. {
  194.   switch(Trans_Type)
  195.   {
  196.     case cmdChangeDir: ShowMessage("ChangeDir not supported"); break;
  197.     case cmdMakeDir: ShowMessage("MakeDir not supported"); break;
  198.     case cmdDelete: ShowMessage("Delete not supported"); break;
  199.     case cmdRemoveDir: ShowMessage("RemoveDir not supported"); break;
  200.     case cmdList: ShowMessage("List not supported"); break;
  201.     case cmdRename: ShowMessage("Rename not supported"); break;
  202.     case cmdUpRestore: ShowMessage("UploadRestore not supported"); break;
  203.     case cmdDownRestore: ShowMessage("DownloadRestore not supported"); break;
  204.     case cmdDownload: ShowMessage("Download not supported"); break;
  205.     case cmdUpload: ShowMessage("Upload not supported"); break;
  206.     case cmdAppend: ShowMessage("UploadAppend not supported"); break;
  207.     case cmdReInit: ShowMessage("ReInit not supported"); break;
  208.     case cmdAllocate: ShowMessage("Allocate not supported"); break;
  209.     case cmdNList: ShowMessage("NList not supported"); break;
  210.     case cmdDoCommand: ShowMessage("DoCommand not supported"); break;
  211.   }
  212. }
  213. //---------------------------------------------------------------------------
  214. void __fastcall TFormMain::FormCreate(TObject *Sender)
  215. {
  216.   TabSheet2->TabVisible=false;
  217.   TabSheet3->TabVisible=false;
  218.        
  219. }
  220. //---------------------------------------------------------------------------