curtis
17小時前 5577f3ba7b9f0319c9b32d7080165207726d1f81
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
{ ==============================================================================
  方法名稱:GetFtpinfo
  引用相依:
  方法描述:向伺服器請求案件上傳所需的 FTP 連線資訊。核心邏輯:
            1. 發送包含案件編號與動作代碼的 HTTP POST 請求至後台 Servlet。
            2. 解析伺服器回傳結果,若回傳 'nodata' 則維持 tsNone 模式;若回傳成功,
            則根據標籤判斷是否啟用 FTP 模式 (tsFtp)。
            3. 若為 FTP 模式,會進一步解析並呼叫 DecodeFtpInfo 對包含連線協定、IP、
            Port、帳號及密碼的加密字串進行解密,並存入系統全域變數中。
============================================================================== }
Function TCB_IMGPSScanX.GetFtpinfo(CaseID,Action:String):Boolean;
var
  SendData : String;
 
  Procedure DecodeFtpInfo(EncryStr:String);
  var
    FtpStr : String;
    ftpinfoList : TStringlist;
  begin
    if EncryStr = '' then Exit;
    ftpinfoList := TStringlist.Create;
    try
      FtpStr := En_DecryptionStr_Base64('D',EncryStr,MpsKey);
      SplitString('!@!',FtpStr,ftpinfoList);
      if ftpinfoList[0] = 'ftps' then
        FFtpProtocol := fpftps
      else if ftpinfoList[0] = 'ftp' then
        FFtpProtocol := fpftp;
      FFtpIP := ftpinfoList[1];
      FFtpPort := strtoint(ftpinfoList[2]);
      FFtpID := ftpinfoList[3];
      FFtpPwd := ftpinfoList[4];
 
    finally
    ftpinfoList.Free;
    end;
  end;
begin
  Result := True;
  SendData:='product='+FWork_no+'&case_no='+CaseID+'&department='+FUserUnit+'&action='+Action;
  If not ProcessServlet_FormData(HTTPSClient,FURL+'service/imgpsc/IMGPSC02/ftps',SendData,FReWrite,Memo1,False) Then
  begin
    HttpErrStr := _Msg('錯誤代碼:')+inttostr(HttpError.HttpErrorCode)+','+HttpError.HttpReason;
    Result := False;
    Exit;
  end;
  IF (memo1.Lines.Strings[0] = '1') Then
  begin
    if memo1.Lines.Strings[1]='nodata' then   //nodata 為正常可繼續的判斷
    begin
      TransMode := tsNone;
      Result := True;
      Exit;
    end
    else
    begin
      HttpErrStr := _Msg('錯誤原因:')+memo1.Lines.Strings[1];
      Result := False;
      Exit;
    end;
  end
  Else if Pos('<script type="text/javascript" src="scripts/CW00/login.js"></script>',Memo1.Lines.Text) > 0 then
  begin
    HttpErrStr := _Msg('錯誤原因:')+_Msg('閒置過久或被登出,請重新登入');
    Result := False;
    Exit;
  end
  else if (memo1.Lines.Strings[0] <> '0') then//不認識的字串
  begin
    HttpErrStr := _Msg('錯誤原因:')+memo1.Lines.Strings[0];
    Result := False;
    Exit;
  end;
  TransMode := tsHttp;
  FFtpExtraPath := '';
 
  if memo1.Lines.Strings[0] = '0' then
  begin
    if memo1.Lines.Strings[2] = 'Y' then   //要使用FTP
      TransMode := tsFtp;
    if memo1.Lines.Count > 3 then
    begin
      FFtpExtraPath := memo1.Lines.Strings[3];
      DecodeFtpInfo(memo1.Lines.Strings[4]);
    end;
  end;
end;
 
 
{ ==============================================================================
  方法名稱:SetFtpInfo
  引用相依:IIS_Ftp, SetFtpInfo
  方法描述:將 FTP 連線參數與事件回呼設定至 FTP 傳輸元件 (IIS_Ftp)。此方法會將先
            前取得並解碼的連線資訊(如 FTP IP、帳號、密碼、路徑、連接埠)指派給 IIS_Ft
            p 物件,並根據協定類型設定是否開啟 SSL/TLS 以及被動模式 (Passive)。此
            外,也會關聯各項事件處理器(如 SSLError, CertificateValidate, TextData
            Line 等),以監控傳輸過程中的通訊狀態。
============================================================================== }
Procedure TCB_IMGPSScanX.SetFtpInfo;     //餵入FTP資訊
begin
  IIS_Ftp.Display1 := Display1;
  IIS_Ftp.FTPSClient1 := FTPSClient1;
  IIS_Ftp.ElMemoryCertStorage := ElMemoryCertStorage;
  IIS_Ftp.Display1 := Display1;
  IIS_Ftp.Ftpip := FFtpIP;
  IIS_Ftp.Ftpuserid := FFtpID;
  IIS_Ftp.FtpPwd := FFtpPwd;
  IIS_Ftp.FtpPath := FFtpRootPath;
  IIS_Ftp.FtpPort := FFtpPort;
  IIS_Ftp.FtpSSL := True;
  IIS_Ftp.FtpPassive := True;
  if FFtpProtocol = fpftp then
     IIS_Ftp.FtpSSL := False;
  IIS_Ftp.FtpEncryptDataChannel := true;
  FTPSClient1.OnControlReceiveAsString := IIS_Ftp.EventHandlers.ControlReceiveAsString;
  FTPSClient1.OnControlSendAsString := IIS_Ftp.EventHandlers.ControlSendAsString;
  FTPSClient1.OnSSLError := IIS_Ftp.EventHandlers.SSLError;
  FTPSClient1.OnCertificateValidate := IIS_Ftp.EventHandlers.CertificateValidate;
  FTPSClient1.OnTextDataLine := IIS_Ftp.EventHandlers.TextDataLine;
 
  {Showmessage(Format('Ftpip:%s'+#13
              +'Ftpid:%s'+#13
              +'Ftppwd:%s'+#13
              +'Ftppath:%s'+#13
              +'Ftpport:%s'+#13
              ,[FFtpIP,FFtpid,FFtpPwd,Ftppath,inttostr(Ftpport)]));}
end;
 
 
{ ==============================================================================
  方法名稱:FtpCaseComplete
  引用相依:FtpCaseComplete, ProcessServlet_FormData
  方法描述:通知後台伺服器 FTP 案件上傳已完成。方法會將包含案件狀態的上傳數據發送
            至特定的 Servlet 介面。邏輯包含檢查 HTTP 通訊是否成功、解析伺服器回傳
            的結果代碼,並處理可能的登入過期(Session Timeout)情況。若執行失敗,會將
            錯誤原因記錄至 HttpErrStr,供後續 UI 顯示錯誤訊息。
============================================================================== }
Function TCB_IMGPSScanX.FtpCaseComplete(SendData:String):Boolean;
begin
  Result := True;
  If not ProcessServlet_FormData(HTTPSClient,FURL+'service/imgpsc/IMGPSC02/caseupload',SendData,FReWrite,Memo1,False) Then
  begin
    HttpErrStr := _Msg('錯誤代碼:')+inttostr(HttpError.HttpErrorCode)+','+HttpError.HttpReason;
    Result := False;
    Exit;
  end;
  IF (memo1.Lines.Strings[0] = '1') or (memo1.Lines.Strings[0] <> '0') Then
  begin
    HttpErrStr := _Msg('錯誤原因:')+memo1.Lines.Strings[1];
    Result := False;
    Exit;
  end
  Else if Pos('<script type="text/javascript" src="scripts/CW00/login.js"></script>',Memo1.Lines.Text) > 0 then
  begin
    HttpErrStr := _Msg('錯誤原因:')+_Msg('閒置過久或被登出,請重新登入');
    Result := False;
    Exit;
  end;
end;