Skip to main content
September 2, 2010
Question

How to get a file with <CFFTP>

  • September 2, 2010
  • 1 reply
  • 1840 views

I am trying to grab a file and move it to the coldfusion server using <CFFTP> The server in which I am trying to grab the file is a sftp server. I am running coldfusion 8. When I run my code, I dont get an error, I just get a blank white screen, yet the file has not been moved. I will post my code below, does anyone know what I am doing wrong?


<!--- Open conncetion with remote sftpserver --->

        <cftry>
            <cfftp action="open"
                connection="ftpServer"
                server="server.com"
                username = "username"
                password = "password"
                fingerprint = "11:11:B5:F2:11:AF:C2:E2:31:11:D3:B4:11:83:11:11"
                timeout="20"
                port="22"
                secure = "yes" />
            <cfcatch>
                <cfset throwFileTransferFailed("Could not open connection. Message: " & cfcatch.Message & ". Detail: " & cfcatch.Detail)>
            </cfcatch>
        </cftry>

<!--- get the file --->

        <cftry>     
               <cfftp
                action="getFile"
                connection="ftpServer"
                server="server.com"
                username="username"
                password="password"
                remotefile="TEST_20100816.csv"
                localfile="C:\WENS_DEV\pdf\"
                failIfExists="no">
            <cfcatch>
                <cfset throwFileTransferFailed("Could not open connection. Message: " & cfcatch.Message & ". Detail: " & cfcatch.Detail)>
            </cfcatch>
        </cftry>

    This topic has been closed for replies.

    1 reply

    Inspiring
    September 2, 2010

    Things to try:

    1. The value of localfile attribute should probably be a full path including the name of the file, not just a directory.

    2. You should be able to omit the username and password in the getFile CFHTTP tag since you're using an existing connection.

    3. Does the CF service have sufficient rights to write files to the C:\WENS_DEV\pdf\ directory?

    September 2, 2010

    how do I tellif the CF service has sufficient rights?

    Now my code looks like this and I am still getting an error. I cant figure it out.

                <cfftp action="open"
                    connection="ftpServer"
                    server="server.com"
                    username = "username"
                    password = "password"
                    fingerprint = "11:11:11:11:11:11:11:11:11"
                    timeout="30"
                    port="22"
                    secure = "yes" />
       
                   <cfftp
                    action="getFile"
                    connection="ftpServer"
                    remotefile="TEST_20100816.csv"
                    localfile="C:\WENS_DEV\pdf\TEST_20100816.csv"
                    failIfExists="no">

    Inspiring
    September 2, 2010

    After you open the ftp connection, try a listdir.  If nothing else it should tell you that your connection was successful and what's available on the other end.