下面有两部分程序,请大虾帮我看看,哪里出现的问题
procedure TfrmFtpUpDown.FileDataCopy(iup: integer); //上传
var
SearchRec: TSearchRec;
FStream: TIniFile; STxtfilename:string;
bEncoded,UploadAll:boolean;
sUpHost,sUpUSERID,sUpPASSWORD,sUpHOSTDIR:string;
iUpPORT:Cardinal;
iCount:integer;
Begin
{b}try
UPfileSourseList:=TstringList.Create;
UPfileDestList:=TstringList.Create;
STxtfilename:=ExePath + 'TranUpErrorMsg.txt';
AssignFile(OutputFileUp,STxtfilename);
Append(OutputFileUp);
bUpFailture:=false;
FStream := TIniFile.Create(IniFilePath + 'TranUp'+inttostr(iup)+'.ini');
{c1}try
sUpHost:=FStream.ReadString('FTPUP', 'HOST','');
sUpUSERID:=FStream.ReadString('FTPUP', 'USERID','');
sUpPASSWORD:=FStream.ReadString('FTPUP', 'PASSWORD','');
sUpHOSTDIR:=FStream.ReadString('FTPUP', 'HOSTDIR','');
bEncoded:=FStream.ReadBool('FTPUP','Encoded',false);
iUpPORT:=FStream.ReadInteger('FTPUP','PORT',21);
//iUpInterval:=FStream.ReadInteger('OPTIONS','Interval',5);
iUpTRYTIMES:=FStream.ReadInteger('FTPUP','TRYTIMES',3);
if bEncoded then
sUpPASSWORD:=DeCrypt(sUpPASSWORD,'F')
else
begin
FStream.WriteBool('FTPUP','Encoded',true);
sUpPASSWORD:=FStream.ReadString('FTPUP','PASSWORD','');
FStream.WriteString('FTPUP','PASSWORD',EnCrypt(sUpPASSWORD,'F'));
end;
except
writeln(OutputFileUp,datetimetostr(now)+' '+'配置文件设置不对!');
if bshowmessage then
showmessage('配置文件设置不对!');
exit;
{c1}end;
NMFTPUp.Host:=sUpHost;
NMFTPUp.UserID:=sUpUSERID;
NMFTPUp.Timeout := 5000;
NMFTPUp.Password:=sUpPASSWORD;
NMFTPUp.Port:=iUpPORT;
{c2}try
NMFTPUp.Connect;
{d}if NMFTPUp.Connected then
begin
try
if sUpHOSTDIR<>'' then
NMFTPUp.ChangeDir(sUpHOSTDIR);
except
NMFTPUp.Disconnect;
writeln(OutputFileUp,datetimetostr(now)+' '+'FTP-'+sUpHost+','+'上传的目录不存在!');
end;
//sUpFileDir:=sUpDownFilesDIR+'HaveUpFile'+inttostr(iup);
//if not directoryexists(sUpFileDir) then
// createDir(sUpFileDir);
iUpTRYTIMES:=iUpTRYTIMES+1;
iUpTRYTIMESTmp:=iUpTRYTIMES;
{e}while (iUpTRYTIMESTmp=iUpTRYTIMES) or (bUpFailture and (iUpTRYTIMES>0)) do
begin
bUpFailture:=false;
UpfileDestList.Clear;
UPfileSourseList.Clear;
if (FindFirst(sUpDownFilesDIR+'ToBeUpFile'+inttostr(iup)+'\'+'*.*',faArchive,SearchRec)=0) then
repeat
if (UPfileSourseList.IndexOf(SearchRec.Name)=-1) then
begin
UPfileSourseList.Add(SearchRec.Name);
end;
until FindNext(SearchRec)<>0;
UploadAll:=True;
try
if UPfileSourseList.Count>0 then
for iCount:=0 to UPfileSourseList.Count-1 do
begin
sUpSouce:=sUpDownFilesDIR+'ToBeUpFile'+inttostr(iup)+'\'+UPfileSourseList.Strings[iCount];
NMFTPUp.Upload(sUpSouce,extractfilename(sUpSouce));
end;
except
UploadAll:=False;
end;
if (UpfileDestList.Count>0) and UploadAll then
for iCount:=0 to UpfileDestList.Count-1 do
begin
sUpSouce:=sUpDownFilesDIR+'ToBeUpFile'+inttostr(iup)+'\'+UpfileDestList.Strings[iCount];
sUpDest:=sUpDownFilesDIR+'HaveUpFile'+inttostr(iup)+'\'+UpfileDestList.Strings[iCount];
deletefile(sUpDest);
if copyfileto(pchar(sUpSouce),pchar(sUpDest)) then
deletefile(sUpSouce);
end; iUpTRYTIMES:=iUpTRYTIMES-1;
{e}end; SysUtils.FindClose(SearchRec);
NMFTPUp.Disconnect;
{d}end;
except
NMFTPUp.Disconnect;
writeln(OutputFileUp,datetimetostr(now)+' '+'连接不上FTP-'+sUpHost+','+'请检查网络是否连通,用户名密码是否正确!');
if bshowmessage then
showmessage('连接不上FTP-'+sUpHost+','+#13#10+'请检查网络是否连通,用户名密码是否正确!');
{c2}end;
{b}finally
FStream.free;
CloseFile(OutputFileUp);
UpfileDestList.free;
UPfileSourseList.free;
end;
end;
procedure TfrmFtpUpDown.FileDataCopy(iup: integer); //上传
var
SearchRec: TSearchRec;
FStream: TIniFile; STxtfilename:string;
bEncoded,UploadAll:boolean;
sUpHost,sUpUSERID,sUpPASSWORD,sUpHOSTDIR:string;
iUpPORT:Cardinal;
iCount:integer;
Begin
{b}try
UPfileSourseList:=TstringList.Create;
UPfileDestList:=TstringList.Create;
STxtfilename:=ExePath + 'TranUpErrorMsg.txt';
AssignFile(OutputFileUp,STxtfilename);
Append(OutputFileUp);
bUpFailture:=false;
FStream := TIniFile.Create(IniFilePath + 'TranUp'+inttostr(iup)+'.ini');
{c1}try
sUpHost:=FStream.ReadString('FTPUP', 'HOST','');
sUpUSERID:=FStream.ReadString('FTPUP', 'USERID','');
sUpPASSWORD:=FStream.ReadString('FTPUP', 'PASSWORD','');
sUpHOSTDIR:=FStream.ReadString('FTPUP', 'HOSTDIR','');
bEncoded:=FStream.ReadBool('FTPUP','Encoded',false);
iUpPORT:=FStream.ReadInteger('FTPUP','PORT',21);
//iUpInterval:=FStream.ReadInteger('OPTIONS','Interval',5);
iUpTRYTIMES:=FStream.ReadInteger('FTPUP','TRYTIMES',3);
if bEncoded then
sUpPASSWORD:=DeCrypt(sUpPASSWORD,'F')
else
begin
FStream.WriteBool('FTPUP','Encoded',true);
sUpPASSWORD:=FStream.ReadString('FTPUP','PASSWORD','');
FStream.WriteString('FTPUP','PASSWORD',EnCrypt(sUpPASSWORD,'F'));
end;
except
writeln(OutputFileUp,datetimetostr(now)+' '+'配置文件设置不对!');
if bshowmessage then
showmessage('配置文件设置不对!');
exit;
{c1}end;
NMFTPUp.Host:=sUpHost;
NMFTPUp.UserID:=sUpUSERID;
NMFTPUp.Timeout := 5000;
NMFTPUp.Password:=sUpPASSWORD;
NMFTPUp.Port:=iUpPORT;
{c2}try
NMFTPUp.Connect;
{d}if NMFTPUp.Connected then
begin
try
if sUpHOSTDIR<>'' then
NMFTPUp.ChangeDir(sUpHOSTDIR);
except
NMFTPUp.Disconnect;
writeln(OutputFileUp,datetimetostr(now)+' '+'FTP-'+sUpHost+','+'上传的目录不存在!');
end;
//sUpFileDir:=sUpDownFilesDIR+'HaveUpFile'+inttostr(iup);
//if not directoryexists(sUpFileDir) then
// createDir(sUpFileDir);
iUpTRYTIMES:=iUpTRYTIMES+1;
iUpTRYTIMESTmp:=iUpTRYTIMES;
{e}while (iUpTRYTIMESTmp=iUpTRYTIMES) or (bUpFailture and (iUpTRYTIMES>0)) do
begin
bUpFailture:=false;
UpfileDestList.Clear;
UPfileSourseList.Clear;
if (FindFirst(sUpDownFilesDIR+'ToBeUpFile'+inttostr(iup)+'\'+'*.*',faArchive,SearchRec)=0) then
repeat
if (UPfileSourseList.IndexOf(SearchRec.Name)=-1) then
begin
UPfileSourseList.Add(SearchRec.Name);
end;
until FindNext(SearchRec)<>0;
UploadAll:=True;
try
if UPfileSourseList.Count>0 then
for iCount:=0 to UPfileSourseList.Count-1 do
begin
sUpSouce:=sUpDownFilesDIR+'ToBeUpFile'+inttostr(iup)+'\'+UPfileSourseList.Strings[iCount];
NMFTPUp.Upload(sUpSouce,extractfilename(sUpSouce));
end;
except
UploadAll:=False;
end;
if (UpfileDestList.Count>0) and UploadAll then
for iCount:=0 to UpfileDestList.Count-1 do
begin
sUpSouce:=sUpDownFilesDIR+'ToBeUpFile'+inttostr(iup)+'\'+UpfileDestList.Strings[iCount];
sUpDest:=sUpDownFilesDIR+'HaveUpFile'+inttostr(iup)+'\'+UpfileDestList.Strings[iCount];
deletefile(sUpDest);
if copyfileto(pchar(sUpSouce),pchar(sUpDest)) then
deletefile(sUpSouce);
end; iUpTRYTIMES:=iUpTRYTIMES-1;
{e}end; SysUtils.FindClose(SearchRec);
NMFTPUp.Disconnect;
{d}end;
except
NMFTPUp.Disconnect;
writeln(OutputFileUp,datetimetostr(now)+' '+'连接不上FTP-'+sUpHost+','+'请检查网络是否连通,用户名密码是否正确!');
if bshowmessage then
showmessage('连接不上FTP-'+sUpHost+','+#13#10+'请检查网络是否连通,用户名密码是否正确!');
{c2}end;
{b}finally
FStream.free;
CloseFile(OutputFileUp);
UpfileDestList.free;
UPfileSourseList.free;
end;
end;
var
FStream: TIniFile; STxtfilename:string;
bEncoded:boolean; sDownFileDir:string;
sDownHost,sDownUSERID,sDownPASSWORD,sDownHOSTDIR:string;
sDownSERVER,sDownDATEBASENAME:STRING;
iDownPORT:Cardinal;
iCount,i:integer;
FileAtt:string; sEDITYPENAME:string;
Begin
{b}try
DownfileSourseList:=TstringList.Create;
DownfileDestList:=TstringList.Create;
STxtfilename:=ExePath + 'TranDownErrorMsg.txt'; AssignFile(OutputFileDown,STxtfilename);
Append(OutputFileDown);
bDownFailture:=false;
FStream := TIniFile.Create(IniFilePath+'TranDown'+inttostr(idown)+'.ini');
{c1}try
sDownHost:=FStream.ReadString('FTPDOWN', 'HOST','');
sDownUSERID:=FStream.ReadString('FTPDOWN', 'USERID','');
sDownPASSWORD:=FStream.ReadString('FTPDOWN', 'PASSWORD','');
sDownHOSTDIR:=FStream.ReadString('FTPDOWN', 'HOSTDIR','');
sDownHOSTBAKDIR:=FStream.ReadString('FTPDOWN', 'HOSTBAKDIR','');
iDownPORT:=FStream.ReadInteger('FTPDOWN','PORT',21);
bEncoded:=FStream.ReadBool('FTPDOWN','Encoded',false);
//iDownInterval:=FStream.ReadInteger('OPTIONS','Interval',5);
iDownTRYTIMES:=FStream.ReadInteger('FTPDOWN','TRYTIMES',3);
if bEncoded then
sDownPASSWORD:=DeCrypt(sDownPASSWORD,'P')
else
begin
FStream.WriteBool('FTPDOWN','Encoded',true);
sDownPASSWORD:=FStream.ReadString('FTPDOWN','PASSWORD','');
FStream.WriteString('FTPDOWN','PASSWORD',EnCrypt(sDownPASSWORD,'P'));
end;
except
writeln(OutputFileDown,datetimetostr(now)+' '+'配置文件设置不对!');
if bshowmessage then
showmessage('配置文件设置不对!');
exit;
{c1}end;
NMFTPDown.Host:=sDownHost;
NMFTPDown.Port:=iDownPORT;
NMFTPDown.UserID:=sDownUSERID;
NMFTPDown.Timeout := 5000;
NMFTPDown.Password:=sDownPASSWORD;
{c2}try
NMFTPDown.Connect;
{d}if NMFTPDown.Connected then
begin
sDownFileDir:=sUpDownFilesDIR+'DownFile';
//if not directoryexists(sDownFileDir) then
// createDir(sDownFileDir); iDownTRYTIMES:=iDownTRYTIMES+1;
iDownTRYTIMESTmp:=iDownTRYTIMES; {e}while (iDownTRYTIMESTmp=iDownTRYTIMES) or (bDownFailture and (iDownTRYTIMES>0)) do
begin
bDownFailture:=false;
DownfileDestList.Clear;
DownfileSourseList.Clear; NMFTPDown.disConnect;
NMFTPDown.Connect;
if sDownHOSTDIR<>'' then
NMFTPDown.ChangeDir(sDownHOSTDIR); NMFTPDown.ParseList:=true;
NMFTPDown.list;
iCount:=NMFTPDown.FTPDirectoryList.name.Count;
if cbTS.checked then
writeln(OutputFileDown,datetimetostr(now)+'将共下载'+inttostr(iCount)+'个文件');
if (iCount=0) then
begin
NMFTPDown.Disconnect;
exit;
end;
bDownProcess:=true;
for i:=0 to iCount-1 do //down file
begin
//FileAtt:=NMFTPDown.FTPDirectoryList.Attribute.Strings[i];
//if (copy(pchar(FileAtt),1,1)<>'d')and(copy(pchar(FileAtt),1,1)<>'D') then
begin
sDownDest:=NMFTPDown.FTPDirectoryList.name.Strings[i];
sDownSouce:=sDownFileDir+'\'+sDownDest;
NMFTPDown.Download(sDownDest,sDownSouce);
//showmessage();
if cbTS.checked then
writeln(OutputFileDown,datetimetostr(now)+'从'+sDownDest+' 下载到:'+sDownSouce);
end;
end; iCount:=DownfileDestList.Count;
if iCount>0 then
begin
for i:=0 to iCount-1 do //delete have down file
NMFTPDown.Delete(DownfileDestList.Strings[i]); NMFTPDown.Disconnect;
NMFTPDown.Connect; if sDownHOSTBAKDIR<>'' then //backup down file
begin
NMFTPDown.ChangeDir(sDownHOSTBAKDIR);
bDownProcess:=false;
for i:=0 to iCount-1 do
NMFTPDown.Upload(DownfileSourseList.Strings[i],DownfileDestList.Strings[i]);
end;
end; iDownTRYTIMES:=iDownTRYTIMES-1;
{e}end;
NMFTPDown.Disconnect;
{d}end;
except
NMFTPDown.Disconnect;
writeln(OutputFileDown,datetimetostr(now)+' '+'连接不上FTP-'+sDownHost+','+'请检查网络是否连通,用户名密码是否正确!');
if bshowmessage then
showmessage('连接不上FTP-'+sDownHost+','+#13#10+'请检查网络是否连通,用户名密码是否正确!');
{c1}end;
finally
FStream.free;
CloseFile(OutputFileDown);
DownfileSourseList.Free;
DownfileDestList.Free;
{b}end;
end;