get file from ftp with cfftp (coldfusion)

3.5k Views Asked by At

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="[email protected]" <!--- 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?

2

There are 2 best solutions below

0
On BEST ANSWER

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="[email protected]"
    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.

0
On

Did you try sending a blank login ie username="" password="" or "username="anonymous" password=""?

<cfftp action="getFile" 
       username="anonymous" 
       password=""
       ...>