[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

CFLOOP doesn't seem to work - why?

Posted on 2003-03-06
10
Medium Priority
?
192 Views
Last Modified: 2013-12-24
I'm trying to FTP a file that the user has selected to a number of directories on the FTP server.  It only sends the file to the first account.  Can anyone help here?

Here's the code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<CFPARAM name="attributes.Action"             default="Form">
<CFPARAM name="attributes.FTPSrvr"             default="ftp.hud.gov">
<CFPARAM name="attributes.Timeout"               default="1500">

<CFSWITCH expression="#attributes.Action#">

     <CFCASE value="Put">

          <CFFILE ACTION="Upload"
              FILEFIELD="ReleaseNotes"
              DESTINATION="e:\samsweb\ftproot\"
              NAMECONFLICT="overwrite"
               >

          <CFSET localfile = "e:\samsweb\ftproot\#file.serverfile#">
                   
          <CFSET FTPaccounts = StructNew()>
         
          <CFSET val = StructInsert(FTPAccounts, "one"     , "pass1" )>
          <CFSET val = StructInsert(FTPAccounts, "two"     , "pass2" )>
          <CFSET val = StructInsert(FTPaccounts, "three"     , "pass3" )>
          <CFSET val = StructInsert(FTPAccounts, "four"     , "pass4" )>
         
          <CFLOOP collection=#FTPaccounts# item="FTPUser">
               
               <CFFTP
                    connection=HUDFTP
                    timeout="#attributes.Timeout#"
                    server="#attributes.FTPSrvr#"
                    username=#FTPUser#
                    password=#StructFind(FTPaccounts, FTPUser)#
                    action="Open"
                    stoponerror="No"
                 >
               
               <!--- Can Only do all this "stuff" if connection succeeded --->
               <CFIF CFFTP.succeeded is "Yes">
                    <CFFTP
                         connection=HUDFTP
                         timeout="#attributes.Timeout#"
                         action="PutFile"
                         localfile=#localfile#
                         remotefile="#file.serverfile#"
                         transferMode="binary"
                         stoponerror="Yes"
                         >

                    <CFFTP connection=HUDFTP action="Close" stoponerror="No">
                         
               </CFIF>
     
          </CFLOOP>

          <html>
          <head>
               <title>SAMS Release Notes</title>
          </head>
         
          <body>
         
          <table width=100%>
               <tr>
                    <td align="center"><b>The Release Notes file <cfoutput>#file.serverfile#</cfoutput> was successfuly transferred to the HUD FTP site!</b></td>
               </tr>
          </table>
         
          </body>
          </html>    
                                                                 
     </CFCASE>

     <CFCASE value="Form">
     
          <html>
          <head>
               <title>SAMS Release Notes</title>
          </head>
         
          <body>
         
          <form name="relnotes" method="post" action="releasenotes.cfm" enctype="multipart/form-data">
          <input type="hidden" name="attributes.Action" value="Put">
               <table width=100%>
                    <tr>
                         <td align="right">Select the Release Notes :</td>
                         <td align="left"><input type="file" name="ReleaseNotes" size="50"></td>
                    </tr>
                    <tr>
                         <td colspan=2 align="center"><input type="Submit" name="Submit" value="Submit"></td>
                    </tr>
               </table>
          </form>
         
          </body>
          </html>    
     </CFCASE>

</CFSWITCH>                    

0
Comment
Question by:plegg
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 10

Expert Comment

by:substand
ID: 8082330
I can't find any problems with the code, but coldfusion is wierd sometimes.  Have you tried another loop type?

Try:

<CFSET FTPaccounts = StructNew()>
<cfset accntlist="user1,user2,user3,user4">
<cfset passlist="p1,p2,p3,p4">
<cfset counter=0>
<cfloop list="#accntlist#" index="accnt">
<cfset counter=counter+1>
       
              <CFFTP
                   connection=HUDFTP
                   timeout="#attributes.Timeout#"
                   server="#attributes.FTPSrvr#"
                   username=#accnt#
                   password=#listgetat(passlist, counter)#
                   action="Open"
                   stoponerror="No"
                >
             
              <!--- Can Only do all this "stuff" if connection succeeded --->
              <CFIF CFFTP.succeeded is "Yes">
                   <CFFTP
                        connection=HUDFTP
                        timeout="#attributes.Timeout#"
                        action="PutFile"
                        localfile=#localfile#
                        remotefile="#file.serverfile#"
                        transferMode="binary"
                        stoponerror="Yes"
                        >

                   <CFFTP connection=HUDFTP action="Close" stoponerror="No">
                       
              </CFIF>
   
         </CFLOOP>


-----------------------------------------

i know its not the best way to do it, but sometimes doing it a different way helps.

0
 
LVL 17

Expert Comment

by:anandkp
ID: 8085994
hi chk on this

u have a similar variable name for
1. account username = "FTPUser"
2. the loop index = "FTPUser"

try changing the names, so it knows what to pick up when !

that shld do it - i guess !!!

let me know

K'Rgds
Anand
0
 

Author Comment

by:plegg
ID: 8104723
substand, I tried that but the same thing happened.  The file was only FTPd to the first account.  Any other ideas?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 

Author Comment

by:plegg
ID: 8104737
anandkp, don't they need to be the same so that correct value is looped over?
0
 

Author Comment

by:plegg
ID: 8105918
Hey, I figured it out.  Because the name of the connection was the same, the loop used the connection information (username, password) from the first one for all of them.  I changed the connection name, making it dynamic.

I found this on Macromedia's ColdFusion Forums.

This is right straight from the documentation in Studio.

" After you establish a connection with cfftp, you can reuse it to perform additional FTP operations. To do this, you use the connection attribute to define and name an FTP connection object that stores information about the connection. Any additional FTP operations that use the same connection name automatically make use of the information stored in the connection object. This facility helps save connection time and improves file transfer operation performance.

Thnaks for your help anyway.
0
 
LVL 10

Expert Comment

by:substand
ID: 8106313
wow, thats wierd.  i figured it would change the connection details as the loop changed.  ie, reopen the connection since you closed it.  

thats funny.
0
 
LVL 17

Expert Comment

by:anandkp
ID: 8108786
ok - so the change is the name worked for u ...

well the username & the loop index needs to be different - cos the username wld be different than the loopindex -that wld hvae values as 1,2,3,4 ... now i dont think the usernames wld also be as 1,2,3,4 ...

ne-ways

K'Rgds
Anand
0
 

Author Comment

by:plegg
ID: 8110507
anandkp, what are you talking about?  It doesn't matter that the account username and the collection index are the same.  I changed the name of the FTP connection to be #Replace(FTPUser,"-","") because it needs to change every time through the loop (see my last post).  I used replace because some of the accounts have a dash and CF doesn't accept a dash in the connection name - another thing they forgot to mention in their documentation.
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10940455
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation in the Cleanup topic area:

PAQ/Refund

Please leave any comments here within the next four days.

mrichmon
EE Cleanup Volunteer
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 10973091
PAQed, with points refunded (50)

ee_ai_construct - (re-order part number #xm34)
Community Support Moderator
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question