get file from ftp with cfftp (coldfusion) - coldfusion

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.

Related

ColdFusion - Connect to LDAP Server

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.

CFLDAP Invalid Token C

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.

cfftp - error during the FTP getFile operation

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.

CFIMAP Reading emails from all folders

I am using CFIMAP to download email attachments daily. Despite what I have tried so far the script is reading emails from all of my folders instead from only the inbox. Anyone know how to fix this?
This is my code:
<cfimap
server = "mail.example.com"
username = "user#sexample.com"
action="open"
secure="yes"
password = "pass"
connection = "mail.example.com" >
<cfimap
action="GetAll"
folder="Inbox"
name="test"
attachmentpath="e:\testfolder"
GenerateUniqueFilenames="yes"
connection="mail.example.com" >
<cfimap
action="MoveMail"
newfolder="processedEmails"
stoponerror="true"
connection="mail.example.com">
<cfimap action="close" connection = "mail.example.com">
you can try the following code..
<cfimap action="open" connection="Conn" server="serverurl" username="useremail" password="passwrd" secure="yes" port="">
<cfimap action="getall" connection="Conn" name="getAttachments" folder="Inbox" attachmentpath="#GetTempDirectory()#" >
<cfquery dbtype="query" name="getMailAttachments">
select *
from getAttachments
where seen=<cfqueryparam value="no" cfsqltype="cf_sql_varchar">
and ATTACHMENTS is not null
</cfquery>
<cfloop query="getMailAttachments">
<cfimap action="MarkRead" connection = "Conn" uid="#getMailAttachments.UID#">
<cfimap action="movemail" connection = "Conn" newfolder="Read mails" uid="#getMailAttachments.UID#">
</cfloop>

How to upload a file through FTP in coldfusion

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