我已经搜索了档案,但我找不到这个问题的答案。基本上,我正在做的是将多个文件夹和文件通过 FTP 传输到远程服务器。我现在拥有的代码将创建根文件夹,并传输根目录下的 11 个文件以及创建根目录下的所有文件夹。没有发生的是每个文件夹的文件都没有被传输。此外,每次创建文件夹时,都会重新发送根文件夹中的 11 个文件。我附上我的代码和评论。
<!--- Open an FTP connection --->
<cfftp action = "open"
connection = "MyConnection"
username = "#getSiteList.TMS_USERNAME#"
password = "#getSiteList.TMS_PASSWORD#"
server = "#getSiteList.TMS_FTPADDRESS#"
secure = "no"
stopOnError = "yes">
<!--- If an FTP connection has been made --->
<cfif cfftp.Succeeded EQ "YES">
<!--- FTP folder contents --->
<cfset folderName = ListLast(#request.FileURL#, "\\")>
<cfset local_path = "#request.FileURL#">
<cfset remote_path = "#folderName##getSiteList.TMS_DIRECTORY#">
<!--- Loop through the number of folders --->
<cfloop index="i" from="1" to="#NumberOfPages#">
<cfscript>
KeywordStart=getPageBreaks.TMP_PAGESTART[i];
if (i eq NumberOfPages)
{
KeywordEnd=getAllKeywords.RecordCount;
}
else
{
KeywordEnd=getPageBreaks.TMP_PAGESTART[i+1]-1;
}
PageKeywordStart=Trim(getAllKeywords.TML_KEYWORD[KeywordStart]);
PageKeywordRange=PageKeywordStart & " to " & Trim(getAllKeywords.TML_KEYWORD[KeywordEnd]);
KeyFolder=MakeFolderTitle(PageKeywordStart);
request.thisFolder=KeyFolder;
create_remote_folder=KeyFolder;
</cfscript>
<!--- Add slash to end of local path if necessary --->
<cfif Right(local_path, 1) NEQ "\">
<cfset local_path = local_path & "\">
</cfif>
<!--- Add slash to end of remote path if necessary --->
<cfif Right(remote_path, 1) NEQ "/">
<cfset remote_path = remote_path & "/">
</cfif>
<!--- Ensure that the root folder is there. --->
<cfftp action="existsDir"
connection="MyConnection"
directory="#remote_path#/#folderName#"
stopOnError = "no">
<!--- If it doesn't exist create it --->
<cfif cfftp.succeeded NEQ "YES">
<!--- Create directory --->
<cfftp action="createDir"
connection="MyConnection"
directory="#folderName#"
stopOnError = "no">
</cfif>
<!--- Get the local directory contents --->
<cfdirectory directory="#local_path#" name="local_dir_contents" action="list">
<!--- Check if create_remote_folder exists --->
<cfftp action="existsDir"
connection="MyConnection"
directory="#remote_path##create_remote_folder#"
stopOnError = "Yes">
<cfif cfftp.Succeeded NEQ "YES">
<cfoutput>
The following error occured: #cfftp.ErrorCode# : #cfftp.ErrorText#
</cfoutput>
</cfif>
<!--- If it doesn't exist create it --->
<cfif cfftp.succeeded NEQ "YES">
<!--- Create directory --->
<cfftp action="createDir"
connection="MyConnection"
directory="#remote_path##create_remote_folder#"
stopOnError = "Yes">
<cfif cfftp.Succeeded NEQ "YES">
<cfoutput>
The following error occured: #cfftp.ErrorCode# : #cfftp.ErrorText#
</cfoutput>
</cfif>
</cfif>
<!--- Loop through contents and put the file on the SFTP server --->
<cfloop query="local_dir_contents" startrow="1" endrow="20">
<cfif local_dir_contents.type EQ "File">
<!--- Put the file on the server --->
<cfftp action="putFile"
connection="MyConnection"
localFile="#local_path##local_dir_contents.name#"
remoteFile="#remote_path##local_dir_contents.name#"
stoponerror="yes">
<cfif cfftp.Succeeded NEQ "YES">
<cfoutput>
The following error occured: #cfftp.ErrorCode# : #cfftp.ErrorText#
</cfoutput>
</cfif>
<cfelse>
<!--- Recursively call THIS function with the new directory --->
<cfset folderName = ListLast(#request.FileURL#, "\\")>
<cfset local_path = "#request.FileURL#">
<cfset remote_path = "#folderName##getSiteList.TMS_DIRECTORY#">
<cfscript>
KeywordStart=getPageBreaks.TMP_PAGESTART[i];
if (i eq NumberOfPages)
{
KeywordEnd=getAllKeywords.RecordCount;
}
else
{
KeywordEnd=getPageBreaks.TMP_PAGESTART[i+1]-1;
}
PageKeywordStart=Trim(getAllKeywords.TML_KEYWORD[KeywordStart]);
PageKeywordRange=PageKeywordStart & " to " & Trim(getAllKeywords.TML_KEYWORD[KeywordEnd]);
KeyFolder=MakeFolderTitle(PageKeywordStart);
request.thisFolder=KeyFolder;
create_remote_folder=KeyFolder;
</cfscript>
<cfftp action="createDir"
connection="MyConnection"
directory="#remote_path##create_remote_folder#"
stopOnError = "Yes">
<cfif cfftp.Succeeded NEQ "YES">
<cfoutput>
The following error occured: #cfftp.ErrorCode# : #cfftp.ErrorText#
</cfoutput>
</cfif>
</cfif>
</cfloop>
</cfloop>
<cfftp action="close" connection="MyConnection">
</cfif>