Проблемы с CFFTP и рекурсивными каталогами

Я искал в архивах и не нашел ответа на этот вопрос. По сути, то, что я делаю, это 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>

person Bruce Sorge    schedule 25.09.2015    source источник
comment
Самый простой способ отладить это — проверить журнал команд на вашем FTP-сервере. Он расскажет вам, что было отправлено и что на самом деле произошло. Помимо этого помните, что порядок создания каталогов важен для FTP. Вы должны начать сверху и не можете создать каталог, который является дочерним для несуществующего каталога.   -  person Alex    schedule 26.09.2015
comment
Все каталоги являются подкаталогами корневой папки. Внутри других каталогов нет каталогов, только файлы HTML.   -  person Bruce Sorge    schedule 26.09.2015
comment
Я решил пойти по другому пути, поэтому в этой теме это сделано.   -  person Bruce Sorge    schedule 27.09.2015


Ответы (1)


Мне подошли следующие варианты

cfftp(connection=cn,action=RemoveDir,recurse=true,passive=true,name=cfftp,directory=[расположение каталога]);

person Peter    schedule 23.12.2020