cfftp and chmod

posted February 9th 2005 at 1624 EST in 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]]

2 Responses

  1. #1 ben
    2 years, 2 months ago

    how do i install coldfusion.oroinc.net.ftp.FTPClient ?

    Thanks

    Ben

  2. #2 Ed Northby
    1 year, 7 months ago

    Does anyone know how to do this on CF8? I get the following error.
    Object Instantiation Exception.
    Class not found: coldfusion.oroinc.net.ftp.FTPClient

    Thx,

    ~Ed