cfftp and chmod

by @jehiah on 2005-02-09 16:24
Filed under: All, ColdFusion

The <CFFTP> tag is awesome, but there are a few things it lacks. One of those is the ability to set file permissiosn on a file which you just uploaded

These examples are for copying to a linux box, from ColdFusion 6.1 so your mileage may varry.

Normally you have something like this, which will copy the file, but it always get's created as rw for the owner only.

<cfftp action="open" ... connection="ftpConn">
    <cfftp action="putfile" 
        remotefile="/path/to/remote/file.txt" 
        localfile="/path/to/local/file.txt" 
        connection="ftpConn">
<cfftp action="close" connection="ftpConn">

By instantiating the ftp object we can use extra functions like sendSiteCommand() and pass it a command like chmod 644 /path/to/remote/file.txt

We end up with this script which sets the permissions on our file properly.

<cfset ftpConn = createObject("java","coldfusion.oroinc.net.ftp.FTPClient").init()> 
<cfftp action="open" ... connection="ftpConn">
    <cfftp action="putfile" 
        remotefile="/path/to/remote/file.txt" 
        localfile="/path/to/local/file.txt" 
        connection="ftpConn">
    <cfscript>ftpConn.sendSiteCommand("chmod 644 /path/to/remote/file.txt");</cfscript>
<cfftp action="close" connection="ftpConn">

Update

Willy Chang posts a few details about how to perform the chmod operation when ftping to a windows server.

ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [[drive:][path][filename] [/S [/D]]
Subscribe via RSS ı Email
© 2017 - Jehiah Czebotar