?
Solved

CFLOOP doesn't seem to work - why?

Posted on 2003-03-06
10
Medium Priority
?
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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