//函數功能:把ftp 失敗的附件ftp上去
//傳入參數:無
//返回值:是否成功
bool __fastcall TFMain::SendftpTemp()//把ftp 失敗的附件ftp上去
{
String ftpTemp=ExtractFilePath(Application->ExeName) + "ftpTemp";
if(!DirectoryExists(ftpTemp))
{
return false;
}
TSearchRec sr;
int iAttributes = 0;
iAttributes = faDirectory ;
TSearchRec Asr;
int AAttributes = faAnyFile;
if (FindFirst(ftpTemp+"//*.*", iAttributes, sr) == 0)//查找子目錄
{
do
if (((sr.Attr & iAttributes) ==sr.Attr)&&(sr.Name!=".")&&(sr.Name!=".."))
{
//查找子目錄下的所有文件
if(DirectoryExists(ftpTemp+"//"+sr.Name +"//Main"))
{
//ftp主檔和Pdf檔
if (FindFirst(ftpTemp+"//"+sr.Name +"//Main//*.*", AAttributes, Asr) == 0)
{
NMFTP1->MakeDirectory("/"+sr.Name);
NMFTP1->MakeDirectory("/"+sr.Name+"/Main");
do
if (((Asr.Attr & AAttributes) ==Asr.Attr)&&(Asr.Name!=".")&&(Asr.Name!=".."))
{
NMFTP1->ChangeDir ("/"+sr.Name+"/Main");
int FileHandle,FSize;
String LocalFile=ftpTemp+"//"+sr.Name +"//Main//"+Asr.Name;
String Remotefile=Asr.Name;
RE->Lines->Add(DateTimeToStr(Now())+":FTP:"+LocalFile);
FileHandle=FileOpen(LocalFile,fmOpenRead);
FSize=FileSeek(FileHandle,0,2);
FileClose(FileHandle);
NMFTP1->Allocate (FSize);
NMFTP1->Upload (LocalFile,Remotefile);
CGPress->AddProgress(2);
Application->ProcessMessages();
}
while (FindNext(Asr)==0);
FindClose(Asr);
}
}
//ftp附件檔
if(DirectoryExists(ftpTemp+"//"+sr.Name +"//Attach"))
{
if (FindFirst(ftpTemp+"//"+sr.Name +"//Attach//*.*", AAttributes, Asr) == 0)
{
NMFTP1->MakeDirectory("/"+sr.Name+"/Attach");
do
if (((Asr.Attr & AAttributes) ==Asr.Attr)&&(Asr.Name!=".")&&(Asr.Name!=".."))
{
NMFTP1->ChangeDir ("/"+sr.Name+"/Attach");
int FileHandle,FSize;
String LocalFile=ftpTemp+"//"+sr.Name +"//Attach//"+Asr.Name;
String Remotefile=Asr.Name;
RE->Lines->Add(DateTimeToStr(Now())+":FTP:"+LocalFile);
FileHandle=FileOpen(LocalFile,fmOpenRead);
FSize=FileSeek(FileHandle,0,2);
FileClose(FileHandle);
NMFTP1->Allocate (FSize);
NMFTP1->Upload (LocalFile,Remotefile);
CGPress->AddProgress(2);
Application->ProcessMessages();
}
while (FindNext(Asr)==0);
FindClose(Asr);
}
}
}
while (FindNext(sr)==0);
FindClose(sr);
}
MyDeleteTree(ftpTemp);
NMFTP1->Disconnect();
return true;
}