首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

关于从FTp服务器取回文件写入数据表时提示:file not found

2012-02-10 
求教:关于从FTp服务器取回文件写入数据表时提示:file not found现在的问题是:单独下载没有问题;单独写入数

求教:关于从FTp服务器取回文件写入数据表时提示:file not found


现在的问题是:单独下载没有问题;单独写入数据表也没有问题;但是如果下载完后接着执行写入数据表,在执行到“ReWrite(ttt) ”时会报“file not found”
错误。苦思数日不得解,特求教产生的原因及解决方案。

相关代码如下:
//按钮触发下载功能:
procedure TFtpDatFrm.Tb_DownLoadCjClick(Sender: TObject);
var
  vYear,vMonth,vDay,vHour,vMinute,vSecond:string;
  V_Year,V_Month:string;
begin
  vYear:=IntToStr(YearOf(Now));

  vMonth:=IntToStr(MonthOf(Now)) ;
  if length(vMonth)=2 then
  vMonth:=vMonth
  else vMonth:='0'+vMonth ;

  vDay:=IntToStr(DayOf(Now)) ;
  if length(vDay)=2 then
  vDay:=vDay
  else vDay:='0'+vDay ;

  if ps_DoneTypy = '0' then
  begin
  if vMonth='12' then
  begin
  V_Year:=IntToStr(YearOf(Now)+1);
  V_Month:='01';
  end
  else
  begin
  V_Year:=vYear;
  V_Month:=IntToStr(MonthOf(Now)+1) ;
  if length(V_Month)=2 then
  V_Month:=V_Month
  else V_Month:='0'+V_Month ;
  end;

  ps_flow:='indent'+V_Year+V_Month ;
  ps_sj:= V_Year+V_Month ;

  if FuncDownLoad(1)=0 then
  begin
  Application.MessageBox(Pchar('下载成功!'),'提示:');
  //ProcUpdateData(1);
  end
  else if FuncDownLoad(1)<>0 then exit
  end
  else
  if ps_DoneTypy='1' then
  begin
  SelectTimeFrm:=TSelectTimeFrm.Create(application);
  if SelectTimeFrm.ShowModal=mrok then
  begin
  ps_flow:='indent'+SelectTimeFrm.ComboBox1.Text+SelectTimeFrm.ComboBox2.Text;;
  ps_sj:= SelectTimeFrm.ComboBox1.Text+SelectTimeFrm.ComboBox2.Text;;

  if FuncDownLoad(1)=0 then
  begin
  Application.MessageBox(Pchar('下载成功!'),'提示:');
  //ProcUpdateData(1);
  end
  else if FuncDownLoad(1)<>0 then exit

  end;
  end;

end;
//下载
function TFtpDatFrm.FuncDownLoad(p_type:integer):integer;
var
  vs_ErrMsg:string;
  Vs_type:string;
begin
  try
  result:=-1;
  if p_type=1 then
  begin
  Vs_type:='采集';
  DelDir(ExtractFilePath(Application.ExeName)+'FilesDownLoad_flow\');
  end;
  if p_type=0 then
  Vs_type:='库存';
  DelDir(ExtractFilePath(Application.ExeName)+'FilesDownLoad_userstore\');
  if FuncConnectFTP(vs_ErrMsg) <> 0 then
  begin
  ProcMemoAdd('连接青铜FTP服务器失败,请检查网络设置,或尝试手工连接是否成功。' + #13 + vs_ErrMsg);
  exit;
  end;
  ProcMemoAdd('连接成功!青铜FTP服务器信息:' + #13 + IdFTP1.SystemDesc);
  if ps_ServerPathDownload <> '' then IdFTP1.ChangeDir(ps_ServerPathDownload);

  //下载文件,保存至本地硬盘(本地目录下的 "FilesDownLoad" 子目录),然后断开连接
  ProcMemoAdd('开始下载'+Vs_type+'文件');
  if FuncDownLoadFile(p_type,vs_ErrMsg) <> 0 then
  begin
  ProcMemoAdd('下载文件时出错!' + #13 + vs_ErrMsg);
  exit;
  end;
  ProcMemoAdd('下载'+Vs_type+'文件成功,保存到程序运行目录下的FilesDownLoad_flow子目录中。');

  //断开FTP服务器 add by jhq 2003-10-10
  ProcMemoAdd('断开与FTP服务器的连接......');
  if IdFTP1.Connected then IdFTP1.Disconnect;
  ProcMemoAdd('已经断开与FTP服务器的连接');
  result:=0;
  finally
  //断开FTP服务器
  if IdFTP1.Connected then
  begin
  ProcMemoAdd('断开与FTP服务器的连接......');
  IdFTP1.Disconnect;
  ProcMemoAdd('已经断开与FTP服务器的连接' + #13);


  end;
  end;
end;
//FTp连接
function TFtpDatFrm.FuncConnectFTP(var AErrMsg: string): integer;
begin
  Result := -1;
  if not IdFTP1.Connected then
  try
  IdFTP1.User := ps_UserName;
  IdFTP1.Password := ps_PassWord;
  IdFTP1.Host := ps_ServerIP;
  IdFTP1.Port := StrToInt(ps_Port);
  IdFTP1.Connect;
  if not IdFTP1.Connected then exit;
  Except
  On E:Exception do
  begin
  ProcMemoAdd( E.Message);
  exit;
  end;
  end;
  Result := 0;

end;
//将数据从文件写入数据表中,Orale9i 
procedure TFtpDatFrm.ProcUpdateData(p_type:integer);
var
  v_i,v_II:integer;
  v_s,v_zmzh,v_spbm,v_xql,V_hdl,v_filename,v_khjlbm,v_cjy,v_khbm,vsql:string;
  ttt,ff:TextFile;
  pInfile:string;
  v_dir,v_filedirname:string;
  FileStream:TFilestream;
begin
  try
  ADOConnection.BeginTrans;
  with Aqry do
  begin
  close;
  sql.Clear;
  if p_type=1 then
  sql.Add('truncate table TEMP_QT_XQHDL');
  if p_type=0 then
  sql.Add('truncate table TEMP_TABLE_KCZ');
  vsql:=Aqry.SQL.text;
  ExecSQL;
  end;
  ADOConnection.CommitTrans;
  except
  on e:exception do
  begin
  ADOConnection.RollbackTrans;
  //Application.MessageBox(pchar('清空青铜数据出错:'+e.Message),'提示');
  ProcMemoAdd('清空青铜数据出错:'+e.Message);
  exit;
  end;
  end;
  v_dir:=ExtractFilePath(Application.ExeName);
  v_filedirname:=v_dir+'new\Imput.ctl';

  AsSignFile(ttt,v_filedirname);
  //if Not FileExists(v_filedirname) then ReWrite(ttt)
  // else Append(ttt);
  if FileExists(v_filedirname) then
  Application.MessageBox(pchar('文件存在'),'提示')
  else Application.MessageBox(pchar('文件不存在'),'提示');
  ReWrite(ttt) ;
  Writeln(ttt,'load data');
  if p_type=1 then
  FlbFiles.ApplyFilePath(ExtractFilePath(Application.ExeName) + 'FilesDownLoad_flow\');
  if p_type=0 then
  FlbFiles.ApplyFilePath(ExtractFilePath(Application.ExeName) + 'FilesDownLoad_userstore\');
  for v_II:=0 to FlbFiles.Items.Count-1 do
  begin
  v_filename:=FlbFiles.Items.Strings[v_II];
  if p_type=1 then
  if Copy(v_filename,length(v_filename)-15,12)=ps_flow then
  Writeln(ttt,'infile '''+ExtractFilePath(Application.ExeName) + 'FilesDownLoad_flow\'+v_filename+'''');
  {if p_type=0 then
  if Copy(v_filename,length(v_filename)-25,22)=ps_userstore then
  Writeln(ttt,'infile '''+ExtractFilePath(Application.ExeName) + 'FilesDownLoad_userstore\'+v_filename+''''); }
  end;
  if p_type=1 then
  begin
  Writeln(ttt,'append into table TEMP_QT_XQHDL ');
  Writeln(ttt,'(khbm POSITION(01:12),spbm POSITION(14:21),CJYXQL POSITION(27:31),CJYHDL POSITION(32:36),SYXQL POSITION(37:41),SYHDL POSITION(42:46),SYXSL POSITION(47:51))');
  end ;
  {else
  begin
  Writeln(ttt,'append into table TEMP_TABLE_KCZ ');
  Writeln(ttt,'(zmzh POSITION(01:12),spbm POSITION(13:23),kcz POSITION(24:33),pdrq POSITION(34:41),cjrq POSITION(42:49))');
  end;}
  CloseFile(ttt);
  AsSignFile(ff,ExtractFilePath(Application.ExeName)+'new\Imput.bat');
  ReWrite(ff) ;
  Writeln(ff,'c:');
  Writeln(ff,'sqlldr userid='+ps_ConnUser+'/'+ps_ConnPassWord+'@'+ps_Sid+' control='+ExtractFilePath(Application.ExeName)+'Imput.ctl');


  CloseFile(ff);
  //ShellExecute(Handle,'open',PChar(ExtractFilePath(Application.ExeName)+'Imput.bat'),nil,Nil,SW_SHOWNORMAL);
  ProcMemoAdd('开始将青铜数据导入数据库……'); //,待数据导入完毕后,点击OK按钮继续下一步
  WaitOnProgram(PChar(ExtractFilePath(Application.ExeName)+'Imput.bat'));
  ProcMemoAdd('青铜数据成功导入数据库!');
  ProcMemoAdd('开始分析数据!');

  try
  ADOConnection.BeginTrans;
  with ADOQueryDelete do
  begin
  close;
  sql.Clear;
  sql.Add('delete from temp_qt_xqhdl where spbm not in (select spbm from jysys.jc_sp)');
  vsql:=ADOQueryDelete.SQL.text;
  ExecSQL;
  end;
  ADOConnection.CommitTrans;
  except
  on e:exception do
  begin
  ADOConnection.RollbackTrans;
  //Application.MessageBox(pchar('处理商品数据出错:'+e.Message),'提示');
  exit;
  end;
  end;

  if FuncUpdateData(p_type,ps_SJ)=0 then
  ProcMemoAdd('分析数据成功!')
  else
  ProcMemoAdd('分析数据失败!') ;
end;


[解决办法]
好长啊
[解决办法]
文件写入可能没有成功

热点排行