plegg
asked on
CFLOOP doesn't seem to work - why?
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.Ac tion#">
<CFCASE value="Put">
<CFFILE ACTION="Upload"
FILEFIELD="ReleaseNotes"
DESTINATION="e:\samsweb\ft proot\"
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.Timeo ut#"
server="#attributes.FTPSrv r#"
username=#FTPUser#
password=#StructFind(FTPac counts, FTPUser)#
action="Open"
stoponerror="No"
>
<!--- Can Only do all this "stuff" if connection succeeded --->
<CFIF CFFTP.succeeded is "Yes">
<CFFTP
connection=HUDFTP
timeout="#attributes.Timeo ut#"
action="PutFile"
localfile=#localfile#
remotefile="#file.serverfi le#"
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 #</cfoutpu t> 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-da ta">
<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>
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.Ac
<CFCASE value="Put">
<CFFILE ACTION="Upload"
FILEFIELD="ReleaseNotes"
DESTINATION="e:\samsweb\ft
NAMECONFLICT="overwrite"
>
<CFSET localfile = "e:\samsweb\ftproot\#file.
<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.Timeo
server="#attributes.FTPSrv
username=#FTPUser#
password=#StructFind(FTPac
action="Open"
stoponerror="No"
>
<!--- Can Only do all this "stuff" if connection succeeded --->
<CFIF CFFTP.succeeded is "Yes">
<CFFTP
connection=HUDFTP
timeout="#attributes.Timeo
action="PutFile"
localfile=#localfile#
remotefile="#file.serverfi
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
</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-da
<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>
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
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
ASKER
substand, I tried that but the same thing happened. The file was only FTPd to the first account. Any other ideas?
ASKER
anandkp, don't they need to be the same so that correct value is looped over?
ASKER
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.
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.
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.
thats funny.
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
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
ASKER
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.
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try:
<CFSET FTPaccounts = StructNew()>
<cfset accntlist="user1,user2,use
<cfset passlist="p1,p2,p3,p4">
<cfset counter=0>
<cfloop list="#accntlist#" index="accnt">
<cfset counter=counter+1>
<CFFTP
connection=HUDFTP
timeout="#attributes.Timeo
server="#attributes.FTPSrv
username=#accnt#
password=#listgetat(passli
action="Open"
stoponerror="No"
>
<!--- Can Only do all this "stuff" if connection succeeded --->
<CFIF CFFTP.succeeded is "Yes">
<CFFTP
connection=HUDFTP
timeout="#attributes.Timeo
action="PutFile"
localfile=#localfile#
remotefile="#file.serverfi
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.