Delphi - Indy TIdFTPServer封装类
<p>在Delphi 7开发下有强大的Indy控件,版本为9,要实现一个FTP服务器,参考自带的例子,发现还要写很多函数,而且不支持中文显示文件列表等等。</p><p>于是,自己改进封装了下,形成一个TFTPServer类。</p>
<p>源码如下:</p>
<div class="postBody">
<div id="cnblogs_post_body" class="blogpost-body ">
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">*******************************************************</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">2</span> <span style="color: rgba(0, 128, 0, 1)">{</span> <span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">3</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)"> 系统名称 FTP服务器类 </span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">4</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)"> 版权所有 (C) http://blog.csdn.net/akof1314 </span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">5</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)"> 单元名称 FTPServer.pas </span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">6</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)"> 单元功能 在Delphi 7下TIdFTPServer实现FTP服务器</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">7</span> <span style="color: rgba(0, 128, 0, 1)">{</span> <span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">8</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">*******************************************************</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">9</span> <span style="color: rgba(0, 0, 255, 1)">unit</span><span style="color: rgba(0, 0, 0, 1)"> FTPServer;
</span><span style="color: rgba(0, 128, 128, 1)"> 10</span>
<span style="color: rgba(0, 128, 128, 1)"> 11</span> <span style="color: rgba(0, 0, 255, 1)">interface</span>
<span style="color: rgba(0, 128, 128, 1)"> 12</span>
<span style="color: rgba(0, 128, 128, 1)"> 13</span> <span style="color: rgba(0, 0, 255, 1)">uses</span>
<span style="color: rgba(0, 128, 128, 1)"> 14</span> <span style="color: rgba(0, 0, 0, 1)">Classes,Windows,Sysutils,IdFTPList,IdFTPServer,Idtcpserver,IdSocketHandle,Idglobal,IdHashCRC, IdStack;
</span><span style="color: rgba(0, 128, 128, 1)"> 15</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)"> 16</span> <span style="color: rgba(0, 128, 0, 1)">功能:自定义消息,方便与窗体进行消息传递
</span><span style="color: rgba(0, 128, 128, 1)"> 17</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)"> 18</span> <span style="color: rgba(0, 0, 255, 1)">type</span>
<span style="color: rgba(0, 128, 128, 1)"> 19</span> TFtpNotifyEvent = <span style="color: rgba(0, 0, 255, 1)">procedure</span> (ADatetime: TDateTime;AUserIP, AEventMessage: <span style="color: rgba(0, 0, 255, 1)">string</span>) <span style="color: rgba(0, 0, 255, 1)">of</span> <span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 20</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)"> 21</span> <span style="color: rgba(0, 128, 0, 1)">功能:FTP服务器类
</span><span style="color: rgba(0, 128, 128, 1)"> 22</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)"> 23</span> <span style="color: rgba(0, 0, 255, 1)">type</span>
<span style="color: rgba(0, 128, 128, 1)"> 24</span> TFTPServer = <span style="color: rgba(0, 0, 255, 1)">class</span>
<span style="color: rgba(0, 128, 128, 1)"> 25</span> <span style="color: rgba(0, 0, 255, 1)">private</span>
<span style="color: rgba(0, 128, 128, 1)"> 26</span> FUserName,FUserPassword,FBorrowDirectory: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 27</span> <span style="color: rgba(0, 0, 0, 1)"> FBorrowPort: Integer;
</span><span style="color: rgba(0, 128, 128, 1)"> 28</span> <span style="color: rgba(0, 0, 0, 1)"> IdFTPServer: TIdFTPServer;
</span><span style="color: rgba(0, 128, 128, 1)"> 29</span> <span style="color: rgba(0, 0, 0, 1)"> FOnFtpNotifyEvent: TFtpNotifyEvent;
</span><span style="color: rgba(0, 128, 128, 1)"> 30</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> IdFTPServer1UserLogin( ASender: TIdFTPServerThread; <span style="color: rgba(0, 0, 255, 1)">const</span> AUsername, APassword: <span style="color: rgba(0, 0, 255, 1)">string</span>; <span style="color: rgba(0, 0, 255, 1)">var</span><span style="color: rgba(0, 0, 0, 1)"> AAuthenticated: Boolean ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 31</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> IdFTPServer1ListDirectory( ASender: TIdFTPServerThread; <span style="color: rgba(0, 0, 255, 1)">const</span> APath: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">; ADirectoryListing: TIdFTPListItems ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 32</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> IdFTPServer1RenameFile( ASender: TIdFTPServerThread; <span style="color: rgba(0, 0, 255, 1)">const</span> ARenameFromFile, ARenameToFile: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 33</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> IdFTPServer1RetrieveFile( ASender: TIdFTPServerThread; <span style="color: rgba(0, 0, 255, 1)">const</span> AFilename: <span style="color: rgba(0, 0, 255, 1)">string</span>; <span style="color: rgba(0, 0, 255, 1)">var</span><span style="color: rgba(0, 0, 0, 1)"> VStream: TStream ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 34</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> IdFTPServer1StoreFile( ASender: TIdFTPServerThread; <span style="color: rgba(0, 0, 255, 1)">const</span> AFilename: <span style="color: rgba(0, 0, 255, 1)">string</span>; AAppend: Boolean; <span style="color: rgba(0, 0, 255, 1)">var</span><span style="color: rgba(0, 0, 0, 1)"> VStream: TStream ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 35</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> IdFTPServer1RemoveDirectory( ASender: TIdFTPServerThread; <span style="color: rgba(0, 0, 255, 1)">var</span> VDirectory: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 36</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> IdFTPServer1MakeDirectory( ASender: TIdFTPServerThread; <span style="color: rgba(0, 0, 255, 1)">var</span> VDirectory: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 37</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> IdFTPServer1GetFileSize( ASender: TIdFTPServerThread; <span style="color: rgba(0, 0, 255, 1)">const</span> AFilename: <span style="color: rgba(0, 0, 255, 1)">string</span>; <span style="color: rgba(0, 0, 255, 1)">var</span><span style="color: rgba(0, 0, 0, 1)"> VFileSize: Int64 ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 38</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> IdFTPServer1DeleteFile( ASender: TIdFTPServerThread; <span style="color: rgba(0, 0, 255, 1)">const</span> APathname: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 39</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> IdFTPServer1ChangeDirectory( ASender: TIdFTPServerThread; <span style="color: rgba(0, 0, 255, 1)">var</span> VDirectory: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 40</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1CommandXCRC( ASender: TIdCommand ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 41</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1DisConnect( AThread: TIdPeerThread ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 42</span> <span style="color: rgba(0, 0, 255, 1)">protected</span>
<span style="color: rgba(0, 128, 128, 1)"> 43</span> <span style="color: rgba(0, 0, 255, 1)">function</span> TransLatePath( <span style="color: rgba(0, 0, 255, 1)">const</span> APathname, homeDir: <span style="color: rgba(0, 0, 255, 1)">string</span> ) : <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 44</span> <span style="color: rgba(0, 0, 255, 1)">public</span>
<span style="color: rgba(0, 128, 128, 1)"> 45</span> <span style="color: rgba(0, 0, 255, 1)">constructor</span> <span style="color: rgba(0, 0, 255, 1)">Create</span>; <span style="color: rgba(0, 0, 255, 1)">reintroduce</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 46</span> <span style="color: rgba(0, 0, 255, 1)">destructor</span> <span style="color: rgba(0, 0, 255, 1)">Destroy</span>; <span style="color: rgba(0, 0, 255, 1)">override</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 47</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> Run;
</span><span style="color: rgba(0, 128, 128, 1)"> 48</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> Stop;
</span><span style="color: rgba(0, 128, 128, 1)"> 49</span> <span style="color: rgba(0, 0, 255, 1)">function</span> GetBindingIP():<span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 50</span> <span style="color: rgba(0, 0, 255, 1)">property</span> UserName: <span style="color: rgba(0, 0, 255, 1)">string</span> <span style="color: rgba(0, 0, 255, 1)">read</span> FUserName <span style="color: rgba(0, 0, 255, 1)">write</span><span style="color: rgba(0, 0, 0, 1)"> FUserName;
</span><span style="color: rgba(0, 128, 128, 1)"> 51</span> <span style="color: rgba(0, 0, 255, 1)">property</span> UserPassword: <span style="color: rgba(0, 0, 255, 1)">string</span> <span style="color: rgba(0, 0, 255, 1)">read</span> FUserPassword <span style="color: rgba(0, 0, 255, 1)">write</span><span style="color: rgba(0, 0, 0, 1)"> FUserPassword;
</span><span style="color: rgba(0, 128, 128, 1)"> 52</span> <span style="color: rgba(0, 0, 255, 1)">property</span> BorrowDirectory: <span style="color: rgba(0, 0, 255, 1)">string</span> <span style="color: rgba(0, 0, 255, 1)">read</span> FBorrowDirectory <span style="color: rgba(0, 0, 255, 1)">write</span><span style="color: rgba(0, 0, 0, 1)"> FBorrowDirectory;
</span><span style="color: rgba(0, 128, 128, 1)"> 53</span> <span style="color: rgba(0, 0, 255, 1)">property</span> BorrowPort: Integer <span style="color: rgba(0, 0, 255, 1)">read</span> FBorrowPort <span style="color: rgba(0, 0, 255, 1)">write</span><span style="color: rgba(0, 0, 0, 1)"> FBorrowPort;
</span><span style="color: rgba(0, 128, 128, 1)"> 54</span> <span style="color: rgba(0, 0, 255, 1)">property</span> OnFtpNotifyEvent: TFtpNotifyEvent <span style="color: rgba(0, 0, 255, 1)">read</span> FOnFtpNotifyEvent <span style="color: rgba(0, 0, 255, 1)">write</span><span style="color: rgba(0, 0, 0, 1)"> FOnFtpNotifyEvent;
</span><span style="color: rgba(0, 128, 128, 1)"> 55</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 56</span>
<span style="color: rgba(0, 128, 128, 1)"> 57</span> <span style="color: rgba(0, 0, 255, 1)">implementation</span>
<span style="color: rgba(0, 128, 128, 1)"> 58</span>
<span style="color: rgba(0, 128, 128, 1)"> 59</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)"> 60</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.Create
</span><span style="color: rgba(0, 128, 128, 1)"> 61</span> <span style="color: rgba(0, 128, 0, 1)">功能: 创建函数
</span><span style="color: rgba(0, 128, 128, 1)"> 62</span> <span style="color: rgba(0, 128, 0, 1)">参数: 无
</span><span style="color: rgba(0, 128, 128, 1)"> 63</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)"> 64</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)"> 65</span> <span style="color: rgba(0, 0, 255, 1)">constructor</span> TFTPServer.<span style="color: rgba(0, 0, 255, 1)">Create</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 66</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)"> 67</span> IdFTPServer := tIdFTPServer.create( <span style="color: rgba(0, 0, 255, 1)">nil</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)"> 68</span> IdFTPServer.DefaultPort := <span style="color: rgba(128, 0, 128, 1)">21</span>; <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">默认端口号</span>
<span style="color: rgba(0, 128, 128, 1)"> 69</span> IdFTPServer.AllowAnonymousLogin := False; <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">是否允许匿名登录</span>
<span style="color: rgba(0, 128, 128, 1)"> 70</span> IdFTPServer.EmulateSystem :=<span style="color: rgba(0, 0, 0, 1)"> ftpsUNIX;
</span><span style="color: rgba(0, 128, 128, 1)"> 71</span> IdFTPServer.HelpReply.text := <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">帮助还未实现!</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 72</span> IdFTPServer.OnChangeDirectory :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1ChangeDirectory;
</span><span style="color: rgba(0, 128, 128, 1)"> 73</span> IdFTPServer.OnGetFileSize :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1GetFileSize;
</span><span style="color: rgba(0, 128, 128, 1)"> 74</span> IdFTPServer.OnListDirectory :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1ListDirectory;
</span><span style="color: rgba(0, 128, 128, 1)"> 75</span> IdFTPServer.OnUserLogin :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1UserLogin;
</span><span style="color: rgba(0, 128, 128, 1)"> 76</span> IdFTPServer.OnRenameFile :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1RenameFile;
</span><span style="color: rgba(0, 128, 128, 1)"> 77</span> IdFTPServer.OnDeleteFile :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1DeleteFile;
</span><span style="color: rgba(0, 128, 128, 1)"> 78</span> IdFTPServer.OnRetrieveFile :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1RetrieveFile;
</span><span style="color: rgba(0, 128, 128, 1)"> 79</span> IdFTPServer.OnStoreFile :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1StoreFile;
</span><span style="color: rgba(0, 128, 128, 1)"> 80</span> IdFTPServer.OnMakeDirectory :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1MakeDirectory;
</span><span style="color: rgba(0, 128, 128, 1)"> 81</span> IdFTPServer.OnRemoveDirectory :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1RemoveDirectory;
</span><span style="color: rgba(0, 128, 128, 1)"> 82</span> IdFTPServer.Greeting.Text.Text := <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">欢迎进入FTP服务器</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 83</span> IdFTPServer.Greeting.NumericCode := <span style="color: rgba(128, 0, 128, 1)">220</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 84</span> IdFTPServer.OnDisconnect :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1DisConnect;
</span><span style="color: rgba(0, 128, 128, 1)"> 85</span> <span style="color: rgba(0, 0, 255, 1)">with</span> IdFTPServer.CommandHandlers.add <span style="color: rgba(0, 0, 255, 1)">do</span>
<span style="color: rgba(0, 128, 128, 1)"> 86</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)"> 87</span> Command := <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">XCRC</span><span style="color: rgba(128, 0, 0, 1)">'</span>; <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">可以迅速验证所下载的文档是否和源文档一样</span>
<span style="color: rgba(0, 128, 128, 1)"> 88</span> OnCommand :=<span style="color: rgba(0, 0, 0, 1)"> IdFTPServer1CommandXCRC;
</span><span style="color: rgba(0, 128, 128, 1)"> 89</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 90</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 91</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)"> 92</span> <span style="color: rgba(0, 128, 0, 1)">过程名: CalculateCRC
</span><span style="color: rgba(0, 128, 128, 1)"> 93</span> <span style="color: rgba(0, 128, 0, 1)">功能: 计算CRC
</span><span style="color: rgba(0, 128, 128, 1)"> 94</span> <span style="color: rgba(0, 128, 0, 1)">参数: const path: string
</span><span style="color: rgba(0, 128, 128, 1)"> 95</span> <span style="color: rgba(0, 128, 0, 1)">返回值: string
</span><span style="color: rgba(0, 128, 128, 1)"> 96</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)"> 97</span> <span style="color: rgba(0, 0, 255, 1)">function</span> CalculateCRC( <span style="color: rgba(0, 0, 255, 1)">const</span> path: <span style="color: rgba(0, 0, 255, 1)">string</span> ) : <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 98</span> <span style="color: rgba(0, 0, 255, 1)">var</span>
<span style="color: rgba(0, 128, 128, 1)"> 99</span> <span style="color: rgba(0, 0, 0, 1)">f: tfilestream;
</span><span style="color: rgba(0, 128, 128, 1)">100</span> <span style="color: rgba(0, 0, 0, 1)">value: dword;
</span><span style="color: rgba(0, 128, 128, 1)">101</span> <span style="color: rgba(0, 0, 0, 1)">IdHashCRC32: TIdHashCRC32;
</span><span style="color: rgba(0, 128, 128, 1)">102</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">103</span> IdHashCRC32 := <span style="color: rgba(0, 0, 255, 1)">nil</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">104</span> f := <span style="color: rgba(0, 0, 255, 1)">nil</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">105</span> <span style="color: rgba(0, 0, 255, 1)">try</span>
<span style="color: rgba(0, 128, 128, 1)">106</span> IdHashCRC32 :=<span style="color: rgba(0, 0, 0, 1)"> TIdHashCRC32.create;
</span><span style="color: rgba(0, 128, 128, 1)">107</span> f := TFileStream.create( path, fmOpenRead <span style="color: rgba(0, 0, 255, 1)">or</span><span style="color: rgba(0, 0, 0, 1)"> fmShareDenyWrite ) ;
</span><span style="color: rgba(0, 128, 128, 1)">108</span> value :=<span style="color: rgba(0, 0, 0, 1)"> IdHashCRC32.HashValue( f ) ;
</span><span style="color: rgba(0, 128, 128, 1)">109</span> result := inttohex( value, <span style="color: rgba(128, 0, 128, 1)">8</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)">110</span> <span style="color: rgba(0, 0, 255, 1)">finally</span>
<span style="color: rgba(0, 128, 128, 1)">111</span> f.<span style="color: rgba(0, 0, 255, 1)">free</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">112</span> IdHashCRC32.<span style="color: rgba(0, 0, 255, 1)">free</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">113</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">114</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">115</span>
<span style="color: rgba(0, 128, 128, 1)">116</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">117</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1CommandXCRC
</span><span style="color: rgba(0, 128, 128, 1)">118</span> <span style="color: rgba(0, 128, 0, 1)">功能: XCRC命令
</span><span style="color: rgba(0, 128, 128, 1)">119</span> <span style="color: rgba(0, 128, 0, 1)">参数: ASender: TIdCommand
</span><span style="color: rgba(0, 128, 128, 1)">120</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">121</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">122</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.IdFTPServer1CommandXCRC( ASender: TIdCommand ) ;
</span><span style="color: rgba(0, 128, 128, 1)">123</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> note, this is made up, and not defined in any rfc.</span>
<span style="color: rgba(0, 128, 128, 1)">124</span> <span style="color: rgba(0, 0, 255, 1)">var</span>
<span style="color: rgba(0, 128, 128, 1)">125</span> s: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">126</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">127</span> <span style="color: rgba(0, 0, 255, 1)">with</span> TIdFTPServerThread( ASender.Thread ) <span style="color: rgba(0, 0, 255, 1)">do</span>
<span style="color: rgba(0, 128, 128, 1)">128</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">129</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Authenticated <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">130</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">131</span> <span style="color: rgba(0, 0, 255, 1)">try</span>
<span style="color: rgba(0, 128, 128, 1)">132</span> s :=<span style="color: rgba(0, 0, 0, 1)"> ProcessPath( CurrentDir, ASender.UnparsedParams ) ;
</span><span style="color: rgba(0, 128, 128, 1)">133</span> s :=<span style="color: rgba(0, 0, 0, 1)"> TransLatePath( s, TIdFTPServerThread( ASender.Thread ) .HomeDir ) ;
</span><span style="color: rgba(0, 128, 128, 1)">134</span> ASender.Reply.SetReply( <span style="color: rgba(128, 0, 128, 1)">213</span><span style="color: rgba(0, 0, 0, 1)">, CalculateCRC( s ) ) ;
</span><span style="color: rgba(0, 128, 128, 1)">135</span> <span style="color: rgba(0, 0, 255, 1)">except</span>
<span style="color: rgba(0, 128, 128, 1)">136</span> ASender.Reply.SetReply( <span style="color: rgba(128, 0, 128, 1)">500</span>, <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">file error</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)">137</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">138</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">139</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">140</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">141</span>
<span style="color: rgba(0, 128, 128, 1)">142</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">143</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.Destroy
</span><span style="color: rgba(0, 128, 128, 1)">144</span> <span style="color: rgba(0, 128, 0, 1)">功能: 析构函数
</span><span style="color: rgba(0, 128, 128, 1)">145</span> <span style="color: rgba(0, 128, 0, 1)">参数: 无
</span><span style="color: rgba(0, 128, 128, 1)">146</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">147</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">148</span> <span style="color: rgba(0, 0, 255, 1)">destructor</span> TFTPServer.<span style="color: rgba(0, 0, 255, 1)">Destroy</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">149</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">150</span> IdFTPServer.<span style="color: rgba(0, 0, 255, 1)">free</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">151</span> <span style="color: rgba(0, 0, 255, 1)">inherited</span><span style="color: rgba(0, 0, 0, 1)"> destroy;
</span><span style="color: rgba(0, 128, 128, 1)">152</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">153</span>
<span style="color: rgba(0, 128, 128, 1)">154</span> <span style="color: rgba(0, 0, 255, 1)">function</span> StartsWith( <span style="color: rgba(0, 0, 255, 1)">const</span> str, substr: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ) : boolean;
</span><span style="color: rgba(0, 128, 128, 1)">155</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">156</span> result := copy( str, <span style="color: rgba(128, 0, 128, 1)">1</span>, length( substr ) ) =<span style="color: rgba(0, 0, 0, 1)"> substr;
</span><span style="color: rgba(0, 128, 128, 1)">157</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">158</span>
<span style="color: rgba(0, 128, 128, 1)">159</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">160</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.Run
</span><span style="color: rgba(0, 128, 128, 1)">161</span> <span style="color: rgba(0, 128, 0, 1)">功能: 开启服务
</span><span style="color: rgba(0, 128, 128, 1)">162</span> <span style="color: rgba(0, 128, 0, 1)">参数: 无
</span><span style="color: rgba(0, 128, 128, 1)">163</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">164</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">165</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.Run;
</span><span style="color: rgba(0, 128, 128, 1)">166</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">167</span> IdFTPServer.DefaultPort :=<span style="color: rgba(0, 0, 0, 1)"> BorrowPort;
</span><span style="color: rgba(0, 128, 128, 1)">168</span> IdFTPServer.Active :=<span style="color: rgba(0, 0, 0, 1)"> True;
</span><span style="color: rgba(0, 128, 128, 1)">169</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">170</span>
<span style="color: rgba(0, 128, 128, 1)">171</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">172</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.Stop
</span><span style="color: rgba(0, 128, 128, 1)">173</span> <span style="color: rgba(0, 128, 0, 1)">功能: 关闭服务
</span><span style="color: rgba(0, 128, 128, 1)">174</span> <span style="color: rgba(0, 128, 0, 1)">参数: 无
</span><span style="color: rgba(0, 128, 128, 1)">175</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">176</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">177</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.Stop;
</span><span style="color: rgba(0, 128, 128, 1)">178</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">179</span> IdFTPServer.Active :=<span style="color: rgba(0, 0, 0, 1)"> False;
</span><span style="color: rgba(0, 128, 128, 1)">180</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">181</span>
<span style="color: rgba(0, 128, 128, 1)">182</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">183</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.GetBindingIP
</span><span style="color: rgba(0, 128, 128, 1)">184</span> <span style="color: rgba(0, 128, 0, 1)">功能: 获取绑定的IP地址
</span><span style="color: rgba(0, 128, 128, 1)">185</span> <span style="color: rgba(0, 128, 0, 1)">参数:
</span><span style="color: rgba(0, 128, 128, 1)">186</span> <span style="color: rgba(0, 128, 0, 1)">返回值: string
</span><span style="color: rgba(0, 128, 128, 1)">187</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">188</span> <span style="color: rgba(0, 0, 255, 1)">function</span> TFTPServer.GetBindingIP():<span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ;
</span><span style="color: rgba(0, 128, 128, 1)">189</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">190</span> Result :=<span style="color: rgba(0, 0, 0, 1)"> GStack.LocalAddress;
</span><span style="color: rgba(0, 128, 128, 1)">191</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">192</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">193</span> <span style="color: rgba(0, 128, 0, 1)">过程名: BackSlashToSlash
</span><span style="color: rgba(0, 128, 128, 1)">194</span> <span style="color: rgba(0, 128, 0, 1)">功能: 反斜杠到斜杠
</span><span style="color: rgba(0, 128, 128, 1)">195</span> <span style="color: rgba(0, 128, 0, 1)">参数: const str: string
</span><span style="color: rgba(0, 128, 128, 1)">196</span> <span style="color: rgba(0, 128, 0, 1)">返回值: string
</span><span style="color: rgba(0, 128, 128, 1)">197</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">198</span> <span style="color: rgba(0, 0, 255, 1)">function</span> BackSlashToSlash( <span style="color: rgba(0, 0, 255, 1)">const</span> str: <span style="color: rgba(0, 0, 255, 1)">string</span> ) : <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">199</span> <span style="color: rgba(0, 0, 255, 1)">var</span>
<span style="color: rgba(0, 128, 128, 1)">200</span> <span style="color: rgba(0, 0, 0, 1)">a: dword;
</span><span style="color: rgba(0, 128, 128, 1)">201</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">202</span> result :=<span style="color: rgba(0, 0, 0, 1)"> str;
</span><span style="color: rgba(0, 128, 128, 1)">203</span> <span style="color: rgba(0, 0, 255, 1)">for</span> a := <span style="color: rgba(128, 0, 128, 1)">1</span> <span style="color: rgba(0, 0, 255, 1)">to</span> length( result ) <span style="color: rgba(0, 0, 255, 1)">do</span>
<span style="color: rgba(0, 128, 128, 1)">204</span> <span style="color: rgba(0, 0, 255, 1)">if</span> result = <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">205</span> result := <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">206</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">207</span>
<span style="color: rgba(0, 128, 128, 1)">208</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">209</span> <span style="color: rgba(0, 128, 0, 1)">过程名: SlashToBackSlash
</span><span style="color: rgba(0, 128, 128, 1)">210</span> <span style="color: rgba(0, 128, 0, 1)">功能: 斜杠到反斜杠
</span><span style="color: rgba(0, 128, 128, 1)">211</span> <span style="color: rgba(0, 128, 0, 1)">参数: const str: string
</span><span style="color: rgba(0, 128, 128, 1)">212</span> <span style="color: rgba(0, 128, 0, 1)">返回值: string
</span><span style="color: rgba(0, 128, 128, 1)">213</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">214</span> <span style="color: rgba(0, 0, 255, 1)">function</span> SlashToBackSlash( <span style="color: rgba(0, 0, 255, 1)">const</span> str: <span style="color: rgba(0, 0, 255, 1)">string</span> ) : <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">215</span> <span style="color: rgba(0, 0, 255, 1)">var</span>
<span style="color: rgba(0, 128, 128, 1)">216</span> <span style="color: rgba(0, 0, 0, 1)">a: dword;
</span><span style="color: rgba(0, 128, 128, 1)">217</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">218</span> result :=<span style="color: rgba(0, 0, 0, 1)"> str;
</span><span style="color: rgba(0, 128, 128, 1)">219</span> <span style="color: rgba(0, 0, 255, 1)">for</span> a := <span style="color: rgba(128, 0, 128, 1)">1</span> <span style="color: rgba(0, 0, 255, 1)">to</span> length( result ) <span style="color: rgba(0, 0, 255, 1)">do</span>
<span style="color: rgba(0, 128, 128, 1)">220</span> <span style="color: rgba(0, 0, 255, 1)">if</span> result = <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">221</span> result := <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">222</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">223</span>
<span style="color: rgba(0, 128, 128, 1)">224</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">225</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.TransLatePath
</span><span style="color: rgba(0, 128, 128, 1)">226</span> <span style="color: rgba(0, 128, 0, 1)">功能: 路径名称翻译
</span><span style="color: rgba(0, 128, 128, 1)">227</span> <span style="color: rgba(0, 128, 0, 1)">参数: const APathname, homeDir: string
</span><span style="color: rgba(0, 128, 128, 1)">228</span> <span style="color: rgba(0, 128, 0, 1)">返回值: string
</span><span style="color: rgba(0, 128, 128, 1)">229</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">230</span> <span style="color: rgba(0, 0, 255, 1)">function</span> TFTPServer.TransLatePath( <span style="color: rgba(0, 0, 255, 1)">const</span> APathname, homeDir: <span style="color: rgba(0, 0, 255, 1)">string</span> ) : <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">231</span> <span style="color: rgba(0, 0, 255, 1)">var</span>
<span style="color: rgba(0, 128, 128, 1)">232</span> tmppath: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">233</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">234</span> result :=<span style="color: rgba(0, 0, 0, 1)"> SlashToBackSlash(Utf8ToAnsi(homeDir) ) ;
</span><span style="color: rgba(0, 128, 128, 1)">235</span> tmppath :=<span style="color: rgba(0, 0, 0, 1)"> SlashToBackSlash( Utf8ToAnsi(APathname) ) ;
</span><span style="color: rgba(0, 128, 128, 1)">236</span> <span style="color: rgba(0, 0, 255, 1)">if</span> homedir = <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">237</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">238</span> result :=<span style="color: rgba(0, 0, 0, 1)"> tmppath;
</span><span style="color: rgba(0, 128, 128, 1)">239</span> <span style="color: rgba(0, 0, 0, 1)"> exit;
</span><span style="color: rgba(0, 128, 128, 1)">240</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">241</span>
<span style="color: rgba(0, 128, 128, 1)">242</span> <span style="color: rgba(0, 0, 255, 1)">if</span> length( APathname ) = <span style="color: rgba(128, 0, 128, 1)">0</span> <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">243</span> <span style="color: rgba(0, 0, 0, 1)"> exit;
</span><span style="color: rgba(0, 128, 128, 1)">244</span> <span style="color: rgba(0, 0, 255, 1)">if</span> result = <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">245</span> result := copy( result, <span style="color: rgba(128, 0, 128, 1)">1</span>, length( result ) - <span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)">246</span> <span style="color: rgba(0, 0, 255, 1)">if</span> tmppath[<span style="color: rgba(128, 0, 128, 1)">1</span>] <> <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">247</span> result := result + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">248</span> result := result +<span style="color: rgba(0, 0, 0, 1)"> tmppath;
</span><span style="color: rgba(0, 128, 128, 1)">249</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">250</span>
<span style="color: rgba(0, 128, 128, 1)">251</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">252</span> <span style="color: rgba(0, 128, 0, 1)">过程名: GetNewDirectory
</span><span style="color: rgba(0, 128, 128, 1)">253</span> <span style="color: rgba(0, 128, 0, 1)">功能: 得到新目录
</span><span style="color: rgba(0, 128, 128, 1)">254</span> <span style="color: rgba(0, 128, 0, 1)">参数: old, action: string
</span><span style="color: rgba(0, 128, 128, 1)">255</span> <span style="color: rgba(0, 128, 0, 1)">返回值: string
</span><span style="color: rgba(0, 128, 128, 1)">256</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">257</span> <span style="color: rgba(0, 0, 255, 1)">function</span> GetNewDirectory( old, action: <span style="color: rgba(0, 0, 255, 1)">string</span> ) : <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">258</span> <span style="color: rgba(0, 0, 255, 1)">var</span>
<span style="color: rgba(0, 128, 128, 1)">259</span> <span style="color: rgba(0, 0, 0, 1)">a: integer;
</span><span style="color: rgba(0, 128, 128, 1)">260</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">261</span> <span style="color: rgba(0, 0, 255, 1)">if</span> action = <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">../</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">262</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">263</span> <span style="color: rgba(0, 0, 255, 1)">if</span> old = <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">264</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">265</span> result :=<span style="color: rgba(0, 0, 0, 1)"> old;
</span><span style="color: rgba(0, 128, 128, 1)">266</span> <span style="color: rgba(0, 0, 0, 1)"> exit;
</span><span style="color: rgba(0, 128, 128, 1)">267</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">268</span> a := length( old ) - <span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">269</span> <span style="color: rgba(0, 0, 255, 1)">while</span> ( old <> <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> ) <span style="color: rgba(0, 0, 255, 1)">and</span> ( old <> <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> ) <span style="color: rgba(0, 0, 255, 1)">do</span>
<span style="color: rgba(0, 128, 128, 1)">270</span> <span style="color: rgba(0, 0, 0, 1)"> dec( a ) ;
</span><span style="color: rgba(0, 128, 128, 1)">271</span> result := copy( old, <span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">, a ) ;
</span><span style="color: rgba(0, 128, 128, 1)">272</span> <span style="color: rgba(0, 0, 0, 1)"> exit;
</span><span style="color: rgba(0, 128, 128, 1)">273</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">274</span> <span style="color: rgba(0, 0, 255, 1)">if</span> ( action[<span style="color: rgba(128, 0, 128, 1)">1</span>] = <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> ) <span style="color: rgba(0, 0, 255, 1)">or</span> ( action[<span style="color: rgba(128, 0, 128, 1)">1</span>] = <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> ) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">275</span> result :=<span style="color: rgba(0, 0, 0, 1)"> action
</span><span style="color: rgba(0, 128, 128, 1)">276</span> <span style="color: rgba(0, 0, 255, 1)">else</span>
<span style="color: rgba(0, 128, 128, 1)">277</span> result := old +<span style="color: rgba(0, 0, 0, 1)"> action;
</span><span style="color: rgba(0, 128, 128, 1)">278</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">279</span>
<span style="color: rgba(0, 128, 128, 1)">280</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">281</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1UserLogin
</span><span style="color: rgba(0, 128, 128, 1)">282</span> <span style="color: rgba(0, 128, 0, 1)">功能: 允许服务器执行一个客户端连接的用户帐户身份验证
</span><span style="color: rgba(0, 128, 128, 1)">283</span> <span style="color: rgba(0, 128, 0, 1)">参数: ASender: TIdFTPServerThread; const AUsername, APassword: string; var AAuthenticated: Boolean
</span><span style="color: rgba(0, 128, 128, 1)">284</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">285</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">286</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.IdFTPServer1UserLogin( ASender: TIdFTPServerThread;
</span><span style="color: rgba(0, 128, 128, 1)">287</span> <span style="color: rgba(0, 0, 255, 1)">const</span> AUsername, APassword: <span style="color: rgba(0, 0, 255, 1)">string</span>; <span style="color: rgba(0, 0, 255, 1)">var</span><span style="color: rgba(0, 0, 0, 1)"> AAuthenticated: Boolean ) ;
</span><span style="color: rgba(0, 128, 128, 1)">288</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">289</span> AAuthenticated := ( AUsername = UserName ) <span style="color: rgba(0, 0, 255, 1)">and</span> ( APassword =<span style="color: rgba(0, 0, 0, 1)"> UserPassword ) ;
</span><span style="color: rgba(0, 128, 128, 1)">290</span> <span style="color: rgba(0, 0, 255, 1)">if</span> <span style="color: rgba(0, 0, 255, 1)">not</span> AAuthenticated <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">291</span> <span style="color: rgba(0, 0, 0, 1)"> exit;
</span><span style="color: rgba(0, 128, 128, 1)">292</span> ASender.HomeDir :=<span style="color: rgba(0, 0, 0, 1)"> AnsiToUtf8(BorrowDirectory);
</span><span style="color: rgba(0, 128, 128, 1)">293</span> asender.currentdir := <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">294</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">295</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">用户登录服务器</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">296</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">297</span>
<span style="color: rgba(0, 128, 128, 1)">298</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">299</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1ListDirectory
</span><span style="color: rgba(0, 128, 128, 1)">300</span> <span style="color: rgba(0, 128, 0, 1)">功能: 允许服务器生成格式化的目录列表
</span><span style="color: rgba(0, 128, 128, 1)">301</span> <span style="color: rgba(0, 128, 0, 1)">参数: ASender: TIdFTPServerThread; const APath: string; ADirectoryListing: TIdFTPListItems
</span><span style="color: rgba(0, 128, 128, 1)">302</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">303</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">304</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> TFTPServer.IdFTPServer1ListDirectory( ASender: TIdFTPServerThread; <span style="color: rgba(0, 0, 255, 1)">const</span> APath: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">; ADirectoryListing: TIdFTPListItems ) ;
</span><span style="color: rgba(0, 128, 128, 1)">305</span>
<span style="color: rgba(0, 128, 128, 1)">306</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> AddlistItem( aDirectoryListing: TIdFTPListItems; Filename: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">; ItemType: TIdDirItemType; size: int64; date: tdatetime ) ;
</span><span style="color: rgba(0, 128, 128, 1)">307</span> <span style="color: rgba(0, 0, 255, 1)">var</span>
<span style="color: rgba(0, 128, 128, 1)">308</span> <span style="color: rgba(0, 0, 0, 1)"> listitem: TIdFTPListItem;
</span><span style="color: rgba(0, 128, 128, 1)">309</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">310</span> listitem :=<span style="color: rgba(0, 0, 0, 1)"> aDirectoryListing.Add;
</span><span style="color: rgba(0, 128, 128, 1)">311</span> listitem.ItemType := ItemType; <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">表示一个文件系统的属性集</span>
<span style="color: rgba(0, 128, 128, 1)">312</span> listitem.FileName := AnsiToUtf8(Filename);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">名称分配给目录中的列表项,这里防止了中文乱码</span>
<span style="color: rgba(0, 128, 128, 1)">313</span> listitem.OwnerName := <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">anonymous</span><span style="color: rgba(128, 0, 0, 1)">'</span>;<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">代表了用户拥有的文件或目录项的名称</span>
<span style="color: rgba(0, 128, 128, 1)">314</span> listitem.GroupName := <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">all</span><span style="color: rgba(128, 0, 0, 1)">'</span>; <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">指定组名拥有的文件名称或目录条目</span>
<span style="color: rgba(0, 128, 128, 1)">315</span> listitem.OwnerPermissions := <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">rwx</span><span style="color: rgba(128, 0, 0, 1)">'</span>; <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">拥有者权限,R读W写X执行</span>
<span style="color: rgba(0, 128, 128, 1)">316</span> listitem.GroupPermissions := <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">rwx</span><span style="color: rgba(128, 0, 0, 1)">'</span>; <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">组拥有者权限</span>
<span style="color: rgba(0, 128, 128, 1)">317</span> listitem.UserPermissions := <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">rwx</span><span style="color: rgba(128, 0, 0, 1)">'</span>;<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">用户权限,基于用户和组权限</span>
<span style="color: rgba(0, 128, 128, 1)">318</span> listitem.Size :=<span style="color: rgba(0, 0, 0, 1)"> size;
</span><span style="color: rgba(0, 128, 128, 1)">319</span> listitem.ModifiedDate :=<span style="color: rgba(0, 0, 0, 1)"> date;
</span><span style="color: rgba(0, 128, 128, 1)">320</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">321</span>
<span style="color: rgba(0, 128, 128, 1)">322</span> <span style="color: rgba(0, 0, 255, 1)">var</span>
<span style="color: rgba(0, 128, 128, 1)">323</span> <span style="color: rgba(0, 0, 0, 1)">f: tsearchrec;
</span><span style="color: rgba(0, 128, 128, 1)">324</span> <span style="color: rgba(0, 0, 0, 1)">a: integer;
</span><span style="color: rgba(0, 128, 128, 1)">325</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">326</span> ADirectoryListing.DirectoryName :=<span style="color: rgba(0, 0, 0, 1)"> apath;
</span><span style="color: rgba(0, 128, 128, 1)">327</span> a := FindFirst( TransLatePath( apath, ASender.HomeDir ) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">*.*</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">, faAnyFile, f ) ;
</span><span style="color: rgba(0, 128, 128, 1)">328</span> <span style="color: rgba(0, 0, 255, 1)">while</span> ( a = <span style="color: rgba(128, 0, 128, 1)">0</span> ) <span style="color: rgba(0, 0, 255, 1)">do</span>
<span style="color: rgba(0, 128, 128, 1)">329</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">330</span> <span style="color: rgba(0, 0, 255, 1)">if</span> ( f.Attr <span style="color: rgba(0, 0, 255, 1)">and</span> faDirectory > <span style="color: rgba(128, 0, 128, 1)">0</span> ) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">331</span> <span style="color: rgba(0, 0, 0, 1)"> AddlistItem( ADirectoryListing, f.Name, ditDirectory, f.size, FileDateToDateTime( f.Time ) )
</span><span style="color: rgba(0, 128, 128, 1)">332</span> <span style="color: rgba(0, 0, 255, 1)">else</span>
<span style="color: rgba(0, 128, 128, 1)">333</span> <span style="color: rgba(0, 0, 0, 1)"> AddlistItem( ADirectoryListing, f.Name, ditFile, f.size, FileDateToDateTime( f.Time ) ) ;
</span><span style="color: rgba(0, 128, 128, 1)">334</span> a :=<span style="color: rgba(0, 0, 0, 1)"> FindNext( f ) ;
</span><span style="color: rgba(0, 128, 128, 1)">335</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">336</span>
<span style="color: rgba(0, 128, 128, 1)">337</span> <span style="color: rgba(0, 0, 0, 1)">FindClose( f ) ;
</span><span style="color: rgba(0, 128, 128, 1)">338</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">339</span>
<span style="color: rgba(0, 128, 128, 1)">340</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">341</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1RenameFile
</span><span style="color: rgba(0, 128, 128, 1)">342</span> <span style="color: rgba(0, 128, 0, 1)">功能: 允许服务器重命名服务器文件系统中的文件
</span><span style="color: rgba(0, 128, 128, 1)">343</span> <span style="color: rgba(0, 128, 0, 1)">参数: ASender: TIdFTPServerThread; const ARenameFromFile, ARenameToFile: string
</span><span style="color: rgba(0, 128, 128, 1)">344</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">345</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">346</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.IdFTPServer1RenameFile( ASender: TIdFTPServerThread;
</span><span style="color: rgba(0, 128, 128, 1)">347</span> <span style="color: rgba(0, 0, 255, 1)">const</span> ARenameFromFile, ARenameToFile: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)">348</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">349</span> <span style="color: rgba(0, 0, 255, 1)">try</span>
<span style="color: rgba(0, 128, 128, 1)">350</span> <span style="color: rgba(0, 0, 255, 1)">if</span> <span style="color: rgba(0, 0, 255, 1)">not</span> MoveFile( pchar( TransLatePath( ARenameFromFile, ASender.HomeDir ) ) , pchar( TransLatePath( ARenameToFile, ASender.HomeDir ) ) ) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">351</span> <span style="color: rgba(0, 0, 0, 1)"> RaiseLastOSError;
</span><span style="color: rgba(0, 128, 128, 1)">352</span> <span style="color: rgba(0, 0, 255, 1)">except</span>
<span style="color: rgba(0, 128, 128, 1)">353</span> on e:Exception <span style="color: rgba(0, 0, 255, 1)">do</span>
<span style="color: rgba(0, 128, 128, 1)">354</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">355</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">356</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">重命名文件[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(ARenameFromFile) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]失败,原因是</span><span style="color: rgba(128, 0, 0, 1)">'</span> +<span style="color: rgba(0, 0, 0, 1)"> e.Message);
</span><span style="color: rgba(0, 128, 128, 1)">357</span> <span style="color: rgba(0, 0, 0, 1)"> Exit;
</span><span style="color: rgba(0, 128, 128, 1)">358</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">359</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">360</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">361</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">重命名文件[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(ARenameFromFile) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]为[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(ARenameToFile) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">362</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">363</span>
<span style="color: rgba(0, 128, 128, 1)">364</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">365</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1RetrieveFile
</span><span style="color: rgba(0, 128, 128, 1)">366</span> <span style="color: rgba(0, 128, 0, 1)">功能: 允许从服务器下载文件系统中的文件
</span><span style="color: rgba(0, 128, 128, 1)">367</span> <span style="color: rgba(0, 128, 0, 1)">参数: ASender: TIdFTPServerThread; const AFilename: string; var VStream: TStream
</span><span style="color: rgba(0, 128, 128, 1)">368</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">369</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">370</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.IdFTPServer1RetrieveFile( ASender: TIdFTPServerThread;
</span><span style="color: rgba(0, 128, 128, 1)">371</span> <span style="color: rgba(0, 0, 255, 1)">const</span> AFilename: <span style="color: rgba(0, 0, 255, 1)">string</span>; <span style="color: rgba(0, 0, 255, 1)">var</span><span style="color: rgba(0, 0, 0, 1)"> VStream: TStream ) ;
</span><span style="color: rgba(0, 128, 128, 1)">372</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">373</span> VStream := TFileStream.<span style="color: rgba(0, 0, 255, 1)">Create</span>( translatepath( AFilename, ASender.HomeDir ) , fmopenread <span style="color: rgba(0, 0, 255, 1)">or</span><span style="color: rgba(0, 0, 0, 1)"> fmShareDenyWrite ) ;
</span><span style="color: rgba(0, 128, 128, 1)">374</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">375</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">下载文件[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(AFilename) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">376</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">377</span>
<span style="color: rgba(0, 128, 128, 1)">378</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">379</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1StoreFile
</span><span style="color: rgba(0, 128, 128, 1)">380</span> <span style="color: rgba(0, 128, 0, 1)">功能: 允许在服务器上传文件系统中的文件
</span><span style="color: rgba(0, 128, 128, 1)">381</span> <span style="color: rgba(0, 128, 0, 1)">参数: ASender: TIdFTPServerThread; const AFilename: string; AAppend: Boolean; var VStream: TStream
</span><span style="color: rgba(0, 128, 128, 1)">382</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">383</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">384</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.IdFTPServer1StoreFile( ASender: TIdFTPServerThread;
</span><span style="color: rgba(0, 128, 128, 1)">385</span> <span style="color: rgba(0, 0, 255, 1)">const</span> AFilename: <span style="color: rgba(0, 0, 255, 1)">string</span>; AAppend: Boolean; <span style="color: rgba(0, 0, 255, 1)">var</span><span style="color: rgba(0, 0, 0, 1)"> VStream: TStream ) ;
</span><span style="color: rgba(0, 128, 128, 1)">386</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">387</span> <span style="color: rgba(0, 0, 255, 1)">if</span> FileExists( translatepath( AFilename, ASender.HomeDir ) ) <span style="color: rgba(0, 0, 255, 1)">and</span> AAppend <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">388</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">389</span> VStream := TFileStream.create( translatepath( AFilename, ASender.HomeDir ) , fmOpenWrite <span style="color: rgba(0, 0, 255, 1)">or</span><span style="color: rgba(0, 0, 0, 1)"> fmShareExclusive ) ;
</span><span style="color: rgba(0, 128, 128, 1)">390</span> VStream.Seek( <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">, soFromEnd ) ;
</span><span style="color: rgba(0, 128, 128, 1)">391</span> <span style="color: rgba(0, 0, 255, 1)">end</span>
<span style="color: rgba(0, 128, 128, 1)">392</span> <span style="color: rgba(0, 0, 255, 1)">else</span>
<span style="color: rgba(0, 128, 128, 1)">393</span> VStream := TFileStream.create( translatepath( AFilename, ASender.HomeDir ) , fmCreate <span style="color: rgba(0, 0, 255, 1)">or</span><span style="color: rgba(0, 0, 0, 1)"> fmShareExclusive ) ;
</span><span style="color: rgba(0, 128, 128, 1)">394</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">395</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">上传文件[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(AFilename) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">396</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">397</span>
<span style="color: rgba(0, 128, 128, 1)">398</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">399</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1RemoveDirectory
</span><span style="color: rgba(0, 128, 128, 1)">400</span> <span style="color: rgba(0, 128, 0, 1)">功能: 允许服务器在服务器删除文件系统的目录
</span><span style="color: rgba(0, 128, 128, 1)">401</span> <span style="color: rgba(0, 128, 0, 1)">参数: ASender: TIdFTPServerThread; var VDirectory: string
</span><span style="color: rgba(0, 128, 128, 1)">402</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">403</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">404</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.IdFTPServer1RemoveDirectory( ASender: TIdFTPServerThread;
</span><span style="color: rgba(0, 128, 128, 1)">405</span> <span style="color: rgba(0, 0, 255, 1)">var</span> VDirectory: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)">406</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">407</span> <span style="color: rgba(0, 0, 255, 1)">try</span>
<span style="color: rgba(0, 128, 128, 1)">408</span> <span style="color: rgba(0, 0, 0, 1)"> RmDir( TransLatePath( VDirectory, ASender.HomeDir ) ) ;
</span><span style="color: rgba(0, 128, 128, 1)">409</span> <span style="color: rgba(0, 0, 255, 1)">except</span>
<span style="color: rgba(0, 128, 128, 1)">410</span> on e:Exception <span style="color: rgba(0, 0, 255, 1)">do</span>
<span style="color: rgba(0, 128, 128, 1)">411</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">412</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">413</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">删除目录[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(VDirectory) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]失败,原因是</span><span style="color: rgba(128, 0, 0, 1)">'</span> +<span style="color: rgba(0, 0, 0, 1)"> e.Message);
</span><span style="color: rgba(0, 128, 128, 1)">414</span> <span style="color: rgba(0, 0, 0, 1)"> Exit;
</span><span style="color: rgba(0, 128, 128, 1)">415</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">416</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">417</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">418</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">删除目录[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(VDirectory) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">419</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">420</span>
<span style="color: rgba(0, 128, 128, 1)">421</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">422</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1MakeDirectory
</span><span style="color: rgba(0, 128, 128, 1)">423</span> <span style="color: rgba(0, 128, 0, 1)">功能: 允许服务器从服务器中创建一个新的子目录
</span><span style="color: rgba(0, 128, 128, 1)">424</span> <span style="color: rgba(0, 128, 0, 1)">参数: ASender: TIdFTPServerThread; var VDirectory: string
</span><span style="color: rgba(0, 128, 128, 1)">425</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">426</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">427</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.IdFTPServer1MakeDirectory( ASender: TIdFTPServerThread;
</span><span style="color: rgba(0, 128, 128, 1)">428</span> <span style="color: rgba(0, 0, 255, 1)">var</span> VDirectory: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)">429</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">430</span> <span style="color: rgba(0, 0, 255, 1)">try</span>
<span style="color: rgba(0, 128, 128, 1)">431</span> <span style="color: rgba(0, 0, 0, 1)"> MkDir( TransLatePath( VDirectory, ASender.HomeDir ) ) ;
</span><span style="color: rgba(0, 128, 128, 1)">432</span> <span style="color: rgba(0, 0, 255, 1)">except</span>
<span style="color: rgba(0, 128, 128, 1)">433</span> on e:Exception <span style="color: rgba(0, 0, 255, 1)">do</span>
<span style="color: rgba(0, 128, 128, 1)">434</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">435</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">436</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">创建目录[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(VDirectory) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]失败,原因是</span><span style="color: rgba(128, 0, 0, 1)">'</span> +<span style="color: rgba(0, 0, 0, 1)"> e.Message);
</span><span style="color: rgba(0, 128, 128, 1)">437</span> <span style="color: rgba(0, 0, 0, 1)"> Exit;
</span><span style="color: rgba(0, 128, 128, 1)">438</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">439</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">440</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">441</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">创建目录[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(VDirectory) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">442</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">443</span>
<span style="color: rgba(0, 128, 128, 1)">444</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">445</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1GetFileSize
</span><span style="color: rgba(0, 128, 128, 1)">446</span> <span style="color: rgba(0, 128, 0, 1)">功能: 允许服务器检索在服务器文件系统的文件的大小
</span><span style="color: rgba(0, 128, 128, 1)">447</span> <span style="color: rgba(0, 128, 0, 1)">参数: ASender: TIdFTPServerThread; const AFilename: string; var VFileSize: Int64
</span><span style="color: rgba(0, 128, 128, 1)">448</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">449</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">450</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.IdFTPServer1GetFileSize( ASender: TIdFTPServerThread;
</span><span style="color: rgba(0, 128, 128, 1)">451</span> <span style="color: rgba(0, 0, 255, 1)">const</span> AFilename: <span style="color: rgba(0, 0, 255, 1)">string</span>; <span style="color: rgba(0, 0, 255, 1)">var</span><span style="color: rgba(0, 0, 0, 1)"> VFileSize: Int64 ) ;
</span><span style="color: rgba(0, 128, 128, 1)">452</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">453</span> VFileSize :=<span style="color: rgba(0, 0, 0, 1)"> FileSizeByName( TransLatePath( AFilename, ASender.HomeDir ) ) ;
</span><span style="color: rgba(0, 128, 128, 1)">454</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">455</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">获取文件大小</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">456</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">457</span>
<span style="color: rgba(0, 128, 128, 1)">458</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">459</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1DeleteFile
</span><span style="color: rgba(0, 128, 128, 1)">460</span> <span style="color: rgba(0, 128, 0, 1)">功能: 允许从服务器中删除的文件系统中的文件
</span><span style="color: rgba(0, 128, 128, 1)">461</span> <span style="color: rgba(0, 128, 0, 1)">参数: ASender: TIdFTPServerThread; const APathname: string
</span><span style="color: rgba(0, 128, 128, 1)">462</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">463</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">464</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.IdFTPServer1DeleteFile( ASender: TIdFTPServerThread;
</span><span style="color: rgba(0, 128, 128, 1)">465</span> <span style="color: rgba(0, 0, 255, 1)">const</span> APathname: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)">466</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">467</span> <span style="color: rgba(0, 0, 255, 1)">try</span>
<span style="color: rgba(0, 128, 128, 1)">468</span> DeleteFile( pchar( TransLatePath( ASender.CurrentDir + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/</span><span style="color: rgba(128, 0, 0, 1)">'</span> +<span style="color: rgba(0, 0, 0, 1)"> APathname, ASender.HomeDir ) ) ) ;
</span><span style="color: rgba(0, 128, 128, 1)">469</span> <span style="color: rgba(0, 0, 255, 1)">except</span>
<span style="color: rgba(0, 128, 128, 1)">470</span> on e:Exception <span style="color: rgba(0, 0, 255, 1)">do</span>
<span style="color: rgba(0, 128, 128, 1)">471</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">472</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">473</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">删除文件[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(APathname) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]失败,原因是</span><span style="color: rgba(128, 0, 0, 1)">'</span> +<span style="color: rgba(0, 0, 0, 1)"> e.Message);
</span><span style="color: rgba(0, 128, 128, 1)">474</span> <span style="color: rgba(0, 0, 0, 1)"> Exit;
</span><span style="color: rgba(0, 128, 128, 1)">475</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">476</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">477</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">478</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">删除文件[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(APathname) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">479</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">480</span>
<span style="color: rgba(0, 128, 128, 1)">481</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">482</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1ChangeDirectory
</span><span style="color: rgba(0, 128, 128, 1)">483</span> <span style="color: rgba(0, 128, 0, 1)">功能: 允许服务器选择一个文件系统路径
</span><span style="color: rgba(0, 128, 128, 1)">484</span> <span style="color: rgba(0, 128, 0, 1)">参数: ASender: TIdFTPServerThread; var VDirectory: string
</span><span style="color: rgba(0, 128, 128, 1)">485</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">486</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">487</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.IdFTPServer1ChangeDirectory( ASender: TIdFTPServerThread;
</span><span style="color: rgba(0, 128, 128, 1)">488</span> <span style="color: rgba(0, 0, 255, 1)">var</span> VDirectory: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> ) ;
</span><span style="color: rgba(0, 128, 128, 1)">489</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">490</span> VDirectory :=<span style="color: rgba(0, 0, 0, 1)"> GetNewDirectory( ASender.CurrentDir, VDirectory ) ;
</span><span style="color: rgba(0, 128, 128, 1)">491</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FOnFtpNotifyEvent) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">492</span> OnFtpNotifyEvent(Now, ASender.Connection.Socket.Binding.PeerIP,<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">进入目录[</span><span style="color: rgba(128, 0, 0, 1)">'</span> + Utf8ToAnsi(VDirectory) + <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">]</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">493</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">494</span>
<span style="color: rgba(0, 128, 128, 1)">495</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------
</span><span style="color: rgba(0, 128, 128, 1)">496</span> <span style="color: rgba(0, 128, 0, 1)">过程名: TFTPServer.IdFTPServer1DisConnect
</span><span style="color: rgba(0, 128, 128, 1)">497</span> <span style="color: rgba(0, 128, 0, 1)">功能: 失去网络连接
</span><span style="color: rgba(0, 128, 128, 1)">498</span> <span style="color: rgba(0, 128, 0, 1)">参数: AThread: TIdPeerThread
</span><span style="color: rgba(0, 128, 128, 1)">499</span> <span style="color: rgba(0, 128, 0, 1)">返回值: 无
</span><span style="color: rgba(0, 128, 128, 1)">500</span> <span style="color: rgba(0, 128, 0, 1)">-------------------------------------------------------------------------------</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">501</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TFTPServer.IdFTPServer1DisConnect( AThread: TIdPeerThread ) ;
</span><span style="color: rgba(0, 128, 128, 1)">502</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">503</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">nothing much here</span>
<span style="color: rgba(0, 128, 128, 1)">504</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">505</span> <span style="color: rgba(0, 0, 255, 1)">end</span>.</pre>
</div>
<p>使用工程示例:</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)"> 1</span> <span style="color: rgba(0, 0, 255, 1)">unit</span><span style="color: rgba(0, 0, 0, 1)"> Unit1;
</span><span style="color: rgba(0, 128, 128, 1)"> 2</span>
<span style="color: rgba(0, 128, 128, 1)"> 3</span> <span style="color: rgba(0, 0, 255, 1)">interface</span>
<span style="color: rgba(0, 128, 128, 1)"> 4</span>
<span style="color: rgba(0, 128, 128, 1)"> 5</span> <span style="color: rgba(0, 0, 255, 1)">uses</span>
<span style="color: rgba(0, 128, 128, 1)"> 6</span> <span style="color: rgba(0, 0, 0, 1)">Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
</span><span style="color: rgba(0, 128, 128, 1)"> 7</span> <span style="color: rgba(0, 0, 0, 1)">Dialogs, StdCtrls, FTPServer;
</span><span style="color: rgba(0, 128, 128, 1)"> 8</span>
<span style="color: rgba(0, 128, 128, 1)"> 9</span> <span style="color: rgba(0, 0, 255, 1)">type</span>
<span style="color: rgba(0, 128, 128, 1)">10</span> TForm1 = <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)">(TForm)
</span><span style="color: rgba(0, 128, 128, 1)">11</span> <span style="color: rgba(0, 0, 0, 1)"> btn1: TButton;
</span><span style="color: rgba(0, 128, 128, 1)">12</span> <span style="color: rgba(0, 0, 0, 1)"> btn2: TButton;
</span><span style="color: rgba(0, 128, 128, 1)">13</span> <span style="color: rgba(0, 0, 0, 1)"> edt_BorrowDirectory: TEdit;
</span><span style="color: rgba(0, 128, 128, 1)">14</span> <span style="color: rgba(0, 0, 0, 1)"> lbl1: TLabel;
</span><span style="color: rgba(0, 128, 128, 1)">15</span> <span style="color: rgba(0, 0, 0, 1)"> mmo1: TMemo;
</span><span style="color: rgba(0, 128, 128, 1)">16</span> <span style="color: rgba(0, 0, 0, 1)"> lbl2: TLabel;
</span><span style="color: rgba(0, 128, 128, 1)">17</span> <span style="color: rgba(0, 0, 0, 1)"> edt_BorrowPort: TEdit;
</span><span style="color: rgba(0, 128, 128, 1)">18</span> <span style="color: rgba(0, 0, 0, 1)"> lbl3: TLabel;
</span><span style="color: rgba(0, 128, 128, 1)">19</span> <span style="color: rgba(0, 0, 0, 1)"> edt_UserName: TEdit;
</span><span style="color: rgba(0, 128, 128, 1)">20</span> <span style="color: rgba(0, 0, 0, 1)"> lbl4: TLabel;
</span><span style="color: rgba(0, 128, 128, 1)">21</span> <span style="color: rgba(0, 0, 0, 1)"> edt_UserPassword: TEdit;
</span><span style="color: rgba(0, 128, 128, 1)">22</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> btn1Click(Sender: TObject);
</span><span style="color: rgba(0, 128, 128, 1)">23</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> btn2Click(Sender: TObject);
</span><span style="color: rgba(0, 128, 128, 1)">24</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> TFTPServer1FtpNotifyEvent(ADatetime: TDateTime;AUserIP, AEventMessage: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">25</span> <span style="color: rgba(0, 0, 255, 1)">private</span>
<span style="color: rgba(0, 128, 128, 1)">26</span> <span style="color: rgba(0, 0, 0, 1)"> FFtpServer: TFTPServer;
</span><span style="color: rgba(0, 128, 128, 1)">27</span> <span style="color: rgba(0, 0, 255, 1)">public</span>
<span style="color: rgba(0, 128, 128, 1)">28</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)"> Public declarations </span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">29</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">30</span>
<span style="color: rgba(0, 128, 128, 1)">31</span> <span style="color: rgba(0, 0, 255, 1)">var</span>
<span style="color: rgba(0, 128, 128, 1)">32</span> <span style="color: rgba(0, 0, 0, 1)">Form1: TForm1;
</span><span style="color: rgba(0, 128, 128, 1)">33</span>
<span style="color: rgba(0, 128, 128, 1)">34</span> <span style="color: rgba(0, 0, 255, 1)">implementation</span>
<span style="color: rgba(0, 128, 128, 1)">35</span>
<span style="color: rgba(0, 128, 128, 1)">36</span>
<span style="color: rgba(0, 128, 128, 1)">37</span>
<span style="color: rgba(0, 128, 128, 1)">38</span> <span style="color: rgba(0, 128, 0, 1)">{</span><span style="color: rgba(0, 128, 0, 1)">$R *.dfm</span><span style="color: rgba(0, 128, 0, 1)">}</span>
<span style="color: rgba(0, 128, 128, 1)">39</span>
<span style="color: rgba(0, 128, 128, 1)">40</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TForm1.btn1Click(Sender: TObject);
</span><span style="color: rgba(0, 128, 128, 1)">41</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">42</span> <span style="color: rgba(0, 0, 255, 1)">if</span> <span style="color: rgba(0, 0, 255, 1)">not</span> Assigned(FFtpServer) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">43</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">44</span> FFtpServer := TFTPServer.<span style="color: rgba(0, 0, 255, 1)">Create</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">45</span> FFtpServer.UserName :=<span style="color: rgba(0, 0, 0, 1)"> Trim(edt_UserName.Text);
</span><span style="color: rgba(0, 128, 128, 1)">46</span> FFtpServer.UserPassword :=<span style="color: rgba(0, 0, 0, 1)"> Trim(edt_UserPassword.Text);
</span><span style="color: rgba(0, 128, 128, 1)">47</span> FFtpServer.BorrowDirectory :=<span style="color: rgba(0, 0, 0, 1)"> Trim(edt_BorrowDirectory.Text);
</span><span style="color: rgba(0, 128, 128, 1)">48</span> FFtpServer.BorrowPort :=<span style="color: rgba(0, 0, 0, 1)"> StrToInt(Trim(edt_BorrowPort.Text));
</span><span style="color: rgba(0, 128, 128, 1)">49</span> FFtpServer.OnFtpNotifyEvent :=<span style="color: rgba(0, 0, 0, 1)"> TFTPServer1FtpNotifyEvent;
</span><span style="color: rgba(0, 128, 128, 1)">50</span> <span style="color: rgba(0, 0, 0, 1)"> FFtpServer.Run;
</span><span style="color: rgba(0, 128, 128, 1)">51</span> mmo1.Lines.Add(DateTimeToStr(Now) + #<span style="color: rgba(128, 0, 128, 1)">32</span> +<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">FTP服务器已开启,本机IP地址:</span><span style="color: rgba(128, 0, 0, 1)">'</span> +<span style="color: rgba(0, 0, 0, 1)"> FFtpServer.GetBindingIP);
</span><span style="color: rgba(0, 128, 128, 1)">52</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">53</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">54</span>
<span style="color: rgba(0, 128, 128, 1)">55</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span><span style="color: rgba(0, 0, 0, 1)"> TForm1.btn2Click(Sender: TObject);
</span><span style="color: rgba(0, 128, 128, 1)">56</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">57</span> <span style="color: rgba(0, 0, 255, 1)">if</span> Assigned(FFtpServer) <span style="color: rgba(0, 0, 255, 1)">then</span>
<span style="color: rgba(0, 128, 128, 1)">58</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">59</span> <span style="color: rgba(0, 0, 0, 1)"> FFtpServer.Stop;
</span><span style="color: rgba(0, 128, 128, 1)">60</span> <span style="color: rgba(0, 0, 255, 1)">FreeAndNil</span><span style="color: rgba(0, 0, 0, 1)">(FFtpServer);
</span><span style="color: rgba(0, 128, 128, 1)">61</span> mmo1.Lines.Add(DateTimeToStr(Now) + #<span style="color: rgba(128, 0, 128, 1)">32</span> +<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">FTP服务器已关闭</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">62</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">63</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">64</span>
<span style="color: rgba(0, 128, 128, 1)">65</span> <span style="color: rgba(0, 0, 255, 1)">procedure</span> TForm1.TFTPServer1FtpNotifyEvent(ADatetime: TDateTime;AUserIP, AEventMessage: <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">66</span> <span style="color: rgba(0, 0, 255, 1)">begin</span>
<span style="color: rgba(0, 128, 128, 1)">67</span> mmo1.Lines.Add(DateTimeToStr(ADatetime) + #<span style="color: rgba(128, 0, 128, 1)">32</span> + AUserIP + #<span style="color: rgba(128, 0, 128, 1)">32</span> +<span style="color: rgba(0, 0, 0, 1)"> AEventMessage);
</span><span style="color: rgba(0, 128, 128, 1)">68</span> SendMessage(mmo1.Handle,WM_VSCROLL,SB_PAGEDOWN,<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">69</span> <span style="color: rgba(0, 0, 255, 1)">end</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">70</span> <span style="color: rgba(0, 0, 255, 1)">end</span>. </pre>
</div>
<p> </p>
</div>
<p>结果如下图所示:</p>
<p><img src="http://hi.csdn.net/attachment/201104/29/0_1304059266Bx0Z.gif" alt=""></p>
<p>示例工程源码下载:</p>
<p>http://download.csdn.net/source/3236325</p>
<p> </p>
<p>原博客地址:</p>
<p>http://blog.csdn.net/akof1314/article/details/6371984#comments</p>
<p> </p>
<p>https://www.cnblogs.com/findumars/p/6360865.html</p>
</div>
</div><br><br>
来源:https://www.cnblogs.com/jeremywucnblog/p/11427911.html
頁:
[1]