Skip to main content
Inspiring
July 19, 2008
Question

File transfer between servers

  • July 19, 2008
  • 5 replies
  • 1092 views
I've been using CF for 10 years, but this is the first time I've had occasion to transfer files between servers under CF control. The only way that I can figure out how to do this is to use CFFTP.

After reading the section on CFFTP in "COLDFUSION 8, Advanced Application Development", it seems to me that I'm going to have to transfer the file(s) from server A to my PC, and then from my PC to server B.

Is there any better way to do this than I've described???

Thanks in advance for your help and suggestions.
    This topic has been closed for replies.

    5 replies

    PHRED-SEAuthor
    Inspiring
    July 22, 2008
    I've run several tests with multiple attachements and they all worked so I think I only need to set the directory once, which is right after I open the connection. As long as the connection remains open, the directory is set to where I want the files to go.

    I do close the connection after I leave the loop: <cfloop> ... </cfloop> <cfftp action="close" connection="FTPUpLink">

    Thank you for your suggestions.
    BKBK
    Community Expert
    Community Expert
    July 22, 2008
    I have two remarks. Since the isDefined() condition is just to verify whether the connection is open, the changeDir action should be out of the cfif block. Secondly, I would apply cfftp one more time, after the loop, to close the connection.


    PHRED-SEAuthor
    Inspiring
    July 22, 2008
    After I overcame a few issues with access while transferring the files from the local directory to the default FTP site ("550 Access denied"), I was able to move onto the final step, which was changing from the default FTP site to a virtual directory that I created under the default FTP site. The change directory action, "ChangeDir", worked without a hitch, so the files are now transferred to exactly where I want them to be.

    Thanks for your help.
    BKBK
    Community Expert
    Community Expert
    July 20, 2008
    I assume server B, the one to which you wish to transfer files, is an FTP server. If not, you may use, for example, IIS to turn it into one. That is, if you're on Windows.

    However, my favorite FTP server is FileZilla. You can set it up in five to ten minutes. Just create an account with username and password, and select a directory. Best of all, it is free.

    I'll also assume that server A, the FTP client, has Coldfusion. Then, to transfer files from server A to server B, three cfftp tags are sufficient.

    The first tag opens an FTP connection, giving it a name. The second transfers the file. The third closes the connection, and you're done. It doesn't go better than this example from the Coldfusion FTP livedocs:

    <cfftp connection = "myConnection"
    username = "myUserName"
    password = "myUserName@allaire.com"
    server = "ftp.allaire.com"
    action = "open"
    stopOnError = "Yes">

    <cfftp
    connection = "myConnection"
    action = "putFile"
    name = "uploadFile"
    transferMode = "binary"
    localFile = "C:\files\upload\somewhere.jpg"
    remoteFile = "somewhere_put.jpg">

    <cfftp connection = "myConnection"
    action = "close"
    stopOnError = "Yes">





    Inspiring
    July 20, 2008
    Run a page on Server A that does an ftp get from Server B, or vice versa.