Tuesday, November 26, 2013

FTP made easier with CFFTP - Downloading zip file using cfftp

CFFTP is a powerful feature in coldfusion which allows file operations without hassles. To start with it might throw challenges but then it's not hard to master.

To get a file from a server using FTP. Adobe docs have very detailed explanation of this tag. You can find this here.

1. Open a connection.
                This is not a necessary option but then I'd choose this way.

                  <cfftp action="open" username="webuser" connection="ftpConnection"
                   password="secret" server="testftp.com" stoponerror="Yes" secure="true"
                   timeout="300"/>

                Timeout is optional, I'd rather specify it.

2. GetFile

                Let me give an example for GetFile operation.

                Get the current path using the GetCurrentDir action. This would help us to avoid errors like file not found.

                <cfftp connection=MyFTPConnection action="GetCurrentDir" stoponerror="Yes">


               <cfftp action="getFile" connection="ftpConnection"
                   localfile="/home/data/downloadedFile.zip"
                   remotefile="#cfftp.returnvalue#/gallery/images.zip"
                   transfermode="auto" failifexists="no" timeout="300" passive="true"/>

3. Close the connection

               <cfftp action="close" connection="MyFTPConnection" stoponerror="Yes"/>


Now the required operation can be performed on that. Let me know if any of you have any questions.




No comments:

Post a Comment