I am trying to have a login page authenticate the user using active directory. I keep getting this Invalid token c found... Does anyone know what may be causing this?
<cftry>
<cfldap action="query"
name="AuthenticateUser"
attributes="dn,mail,givenname,sn,samaccountname,memberof"
start="DC=domain,DC=net"
filter="(&(objectclass=user)(samAccountName=#trim(form.username)#))"
server="name.tc.tax"
Port="389"
username="tc\#trim(form.username)#"
password="#trim(form.password)#"
<cfset LoginMessage = "User Authentication Passed">
<cfcatch type="any">
<cfset LoginMessage = "User Authentication Failed">
</cfcatch>
</cftry>
ERROR:
The CFML compiler was processing:
A cfldap tag beginning on line 2, column 9.
A cfldap tag beginning on line 2, column 9.
The error occurred in D:/Web/www/webapps/ldap.cfm: line 12
10 : password="#trim(form.password)#"
11 :
12 : <cfset LoginMessage = "User Authentication Passed">
13 :
14 : <cfcatch type="any">
You do not have a closing ">" on your cfldap tag.
Related
I am using cfldap (ColdFusion 2016) to connect to an LDAP server but the server starts with LDAPS://. ColdFusion throws an error that it is an invalid name. When I try to connect without LDAPS, it throws "An error has occured while executing the query. Below is the full tag I am using.
<cftry>
<cfldap server="#servername#"
username="#username#"
password="#password#"
port="636" action="query"
name="qryName"
start="#start#"
attributes="#attributes#"
filter="#filter#"
scope="SUBTREE"
secure="cfssl_basic">
<cfcatch type="any">
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>
Is there anything missing?
You may need to import the ldap server's certificate or if it is Active Directory the domain's CA certificate into the java keystore.
https://helpx.adobe.com/coldfusion/kb/import-certificates-certificate-stores-coldfusion.html
Also, here is an example os authenticating via Active Directory.
cfldap(
server = "ServerName",
port = 636,
action = "QUERY",
name = "qLDAPLookup",
secure = "CFSSL_BASIC",
username = "MYDOMAIN\#arguments.username#",
password = arguments.password,
start = "dc=MYDOMAIN,dc=MYTLD",
attributes = "cn,userPrincipalName,title,mail",
timeout = "10",
filter = "(sAMAccountName=#arguments.username#)"
);
if (qLDAPLookup.recordCount) {
userAuthenticated = true;
}
You're missing a double quote after #start#. Not sure if that is in your actual code though.
I need to get a file from this ftp server (ftp.cetip.com.br), located in directory /MediaCDI/ with name "20160412.txt".
The complete address is ftp://ftp.cetip.com.br/MediaCDI/20160412.txt. This is an open ftp, but cfftp requires a user and password to connect. I tried omitting it, like this:
<cfftp action = "getFile"
server="ftp.cetip.com.br"
remotefile="/MediaCDI/20160412.txt"
localfile="#Session.wwwrootPath#Temp\cdi.txt">
but this returns an attribute error.
Attribute validation error for tag CFFTP.
It has an invalid attribute
combination: action,localfile,remotefile,server. Possible combinations
are:
Required attributes:
'action,localfile,password,remotefile,server,username'. Optional
attributes:
'asciiextensionlist,attributes,buffersize,failifexists,fingerprint,passive,port,proxybypass,proxyserver,result,retrycount,secure,stoponerror,timeout,transfermode'.
....
How can I do it without user and pass ?
UPDATE
Thanks Leigh and P Mascari.
I tried it
<cfftp connection="Myftp"
server="ftp.cetip.com.br"
username = "anonymous"
password="name#email.com" <!--- valid email --->
action="Open"
stoponerror="Yes"
secure="no">
<p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput><br />
<cfflush>
<cfftp connection="Myftp"
action="changedir"
directory="MediaCDI">
changed<br />
<cfflush>
<cfftp connection="Myftp"
action="getFile"
remoteFile="20160412.txt"
localfile="#Session.wwwrootPath#Temp\teste.txt"
timeout="3000">
done!!<br />
<cfflush>
Error: 425 Unable to build data connection: Connection timed out
.
My problem now is in the third part, i can connect whith anonymous, change dir, but the action getFile timed out. Any idea?
Did you try sending a blank login ie username="" password="" or "username="anonymous" password=""?
<cfftp action="getFile"
username="anonymous"
password=""
...>
Eureka
I found the problem of timeout. FTP uses an active FTP mode, and the application was waiting for a passive mode (PASV). I added the line passive ='yes' and the command worked :). Here is the final code:
<cfftp
connection="Myftp"
server="ftp.cetip.com.br"
username = "anonymous"
password="username#example.com"
action="Open"
stoponerror="Yes"
secure="no">
<p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput><br />
<cfflush>
<cfftp connection="Myftp"
action="changedir"
directory="MediaCDI">
changed<br />
<cfflush>
<cfftp connection="Myftp"
action="getFile"
remoteFile="20160412.txt"
localfile="#Session.wwwrootPath#Temp\test.txt"
timeout="3000"
passive="yes">
donne<br />
<cfflush>
Thank you for your help.
I have searched the archives and I cannot find the answer to this question. Basically, what I am doing is FTP'ing several folders and files to a remote server. The code I have now will create the root folder, and transfer the 11 files that are in the root as well as create all of the folders under the root. What is not happening is the files for each folder are not being transferred. In addition, the 11 files in the root folder get resent each time a folder is being created. I am attaching my code with comments.
<!--- 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>
The following options worked for me
cfftp(connection="cn",action="RemoveDir",recurse=true,passive="true",name="cfftp",directory="[dir location]");
I am trying to get a file from a remote server and getting an error:
An error occurred during the FTP getFile operation.
The code that I have:
<cfsetting requesttimeout = "3600">
<h1>FTP Connect</h1>
<!--- O P E N --->
<cfftp action = "open"
server = "#application.server#"
username="#application.username#"
password="#application.password#"
connection = "#application.connection#"
passive = "#application.passive#">
Did it open connection? <cfoutput>#cfftp.succeeded#</cfoutput><br />
<cfif cfftp.succeeded>
<cfftp action = "LISTDIR"
stopOnError = "Yes"
name = "ListFiles"
directory = "/www/rentproFeed/"
connection = "#application.connection#"
passive = "Yes">
<cfquery dbtype="query" name="GetSomeContents">
SELECT MAX(name) AS latestFeed
FROM ListFiles
</cfquery>
<cfoutput query="GetSomeContents">
<cfset variables.latestProperties = #latestFeed# >
#variables.latestProperties#
</cfoutput>
<cfftp
action="getFile"
connection= "#application.connection#"
remotefile="/www/rentproFeed/#GetSomeContents.latestFeed#"
localfile="#expandpath("../properties-feed/")#properties-feed.BLM"
failIfExists="no">
Did it downloaded the latest feed file? <cfoutput>#cfftp.succeeded#</cfoutput><br />
<!--- <cfdump var="#ListFiles#" > --->
<cfftp action="getFile"
connection="#application.connection#"
remoteFile="/www/rentproFeed/01014.zip"
localFile="#ExpandPath('../properties-feed/latestImages.zip')#"
failifexists="no"
<!--- retrycount="10" --->
>
<cfoutput>
FTP Operation Return Value: #cfftp.returnValue# <br/>
FTP Operation Successful: #cfftp.succeeded# <br/>
FTFP Operation Error Code: #cfftp.errorCode# <br/>
FTP Operation Error Message: #cfftp.errorCode#<br/>
FTP Operation Error Message: #cfftp.errorText# <br/>
</cfoutput>
</cfif>
<cfftp action="close" connection="#application.connection#" stopOnError="yes">
Did it closed connection? <cfoutput>#cfftp.succeeded#</cfoutput>
<cfabort>
The error occurs when I want to get the "01014.zip" file. The previous getFile action works fine. Can anyone see some problem with my code? Any help would be appreciated.
I found the solution to my problem: The .zip file has 15MB and by default the cfftp timeout is 30 seconds. I increased the timeout and it solved it.
I used below code to upload a file through FTP. From Line: 9 to 14, ít is showing error that "The attribute 'connection' is not valid for the tag. (Found: [connection, localfile, passive, action, failifexists, remotefile])" Please let me know where I went wrong. Thanks in advance
1.<cftry>
2. <cfftp connection="Myftp"
3. action="open"
4. server="#ftpurl#"
5. username="#form.ftpusername#"
6. password="#form.ftppassword#">
7. stoponerror="Yes">
8. Did it open connection? <cfoutput>#cfftp.succeeded#</cfoutput><br />
9. <cfftp connection = "Myftp"
10. action = "PutFile"
11. localFile="D:\home\\wwwroot\localfile.txt"
12. remoteFile="remotefile.txt"
13. failifexists="no"
14. passive = "Yes">
15. Did it put the file? <cfoutput>#cfftp.succeeded#</cfoutput><br />
16. <cfftp action="close" connection="Myftp">
17. <cfcatch>
18. <cfset errText = "Please enter valid FTP details" />
19. <cfset err = err + 1 />
20. </cfcatch>
21.</cftry>
As per the comments on the question, the "error" here is a bug in CFEclipse dictionary files, resulting in incorrect labelling of "connection" as an invalid attribute.
The code provided is valid and executes correctly.
You've got a closing tag on line 6 which looks out of place.
6. password="#form.ftppassword#">
7. stoponerror="Yes">
should instead be
6. password="#form.ftppassword#"
7. stoponerror="Yes">
to use <cffile> tag is best prectice to upload a file on server instead of <cftfp> tag.
it is easy and compact. see syntax..
<cffile
action = "upload"
destination = "full pathname"
fileField = "form field"
accept = "MIME type|file type"
attributes = "file attribute or list"
mode = "permission"
nameConflict = "behavior"
result = "result name">
example :
<cfset destination = expandPath("www\img\QuesImages") />
<cffile action="Upload"
fileField="QuesPhoto" <!--name of input tag in form-->
destination="#destination#"
nameConflict="Overwrite"
accept="image/jpeg, image/gif, image/png">
Correct parameters are
9. <cfftp connection = "Myftp"
10. action = "PutFile"
11. localFile="D:\home\\wwwroot\localfile.txt"
12. remoteFile="remotefile.txt"
13. stoponerror="Yes"
14. passive = "Yes">`
You can use bellow code to upload a file.........code is contents of a single file
<cfcatch type="any">
<cfoutput>#CFCATCH.message#</cfoutput>
Unable to open FTP. Please check Server / Username / Password and then try again.1
<cfabort>
</cfcatch>
<cfcatch type="Any">
<cfoutput>C:#CFCATCH.message#</cfoutput>
Unable to change directory. Please check server directory and then try again.2
<cfabort>
</cfcatch>
Exists...replacing...
File already exist, Unable to remove. Please check User Access. Error: D:#CFCATCH.message#3
<cfcatch type="Any">
<cfoutput>D:#CFCATCH.message#<br />
#CFCATCH.Detail#
</cfoutput><br />
There was a problem uploading your file. Please check User Access and then try again.4
<cfabort>
</cfcatch>
</cftry>
There was a problem uploading your file. Please try again. Error: #CFCATCH.message#5