Here's what I use, straight from my server, so substitute your variables
where necessary:

<CFSET message = "">

<!--- GET LIST OF CONFIRM FILES --->
<CFDIRECTORY ACTION="LIST" DIRECTORY="#half_confirmdir_local#"
NAME="confirmfiles" FILTER="*.pdv" SORT="datelastmodified ASC">
<CFSET message = message & "#confirmfiles.recordCount# confirm files
found.<BR>">

<CFIF confirmfiles.recordCount>

        <!--- open ftp connection --->
        <CFFTP ACTION="OPEN" STOPONERROR="NO" CONNECTION="half"
PASSIVE="NO"
         SERVER="#half_ftpserver#"  USERNAME="#half_username#"
PASSWORD="#half_password#">

        <CFIF CFFTP.Succeeded>

                <CFSET message = message & "Connection opened to
#half_ftpserver#.<BR>">

                <!--- put each order file --->
                <CFLOOP QUERY="confirmfiles">

                        <CFFTP ACTION="PUTFILE" STOPONERROR="NO"
TRANSFERMODE="ASCII" CONNECTION="half" PASSIVE="No"

LOCALFILE="#half_confirmdir_local#\#confirmfiles.name#"
REMOTEFILE="#half_confirmdir#/#confirmfiles.name#">

                        <CFIF CFFTP.Succeeded>
                                <CFSET message = message & "#name#
uploaded to #half_confirmdir#.<BR>">
                                <CFFILE ACTION="MOVE"

SOURCE="#half_confirmdir_local#\#confirmfiles.name#"

DESTINATION="#half_confirmdir_done#\#confirmfiles.name#">
                                <CFSET message = message &
"#confirmfiles.name# moved to #half_confirmdir_done#.<BR>">
                        <CFELSE>
                                Transfer failed!<BR>
                        </CFIF>

                </CFLOOP>

                <CFFTP ACTION="CLOSE" STOPONERROR="NO" CONNECTION="half">
                <CFIF CFFTP.Succeeded>
                        <CFSET message = message & "Connection to
#half_ftpserver# closed.<BR>">
                <CFELSE>
                        <CFSET message = message & "Error closing
Connection to #half_ftpserver#.<BR>">
                </CFIF>

        <CFELSE>

                <CFSET message = message & "Failed to open FTP connection
to #half_ftpserver#.<BR>">

        </CFIF>

</CFIF>

<CFOUTPUT><P>#message#</P></CFOUTPUT>


> Hello All:
>
> ISSUE: CFFTP all .txt files in a given directory.
>
> I'm trying to have code that will FTP all the .txt files in a directory
> to another server. Can anyone help me out here? I would also like to
> know if the files names are in a date format can I perform a range and
> have only certain files be selected for the ftp?
>
> Example of May 17, 2002 = 05172002.txt
>
> Sincerely,
> James Blaha
>
> <CFFTP CONNECTION="movefiles"
> USERNAME="anonymous"
> PASSWORD="guest@unknown"
> SERVER="172.17.89.157"
> ACTION="Open"
> STOPONERROR="Yes">
>
> <!---
> Get a File
> For the get function, both the remote file and the name it will have on
> the local server must be specified. The transfer mode is set explicitly
> here for clarity, but cfftp will usually make the right choice based on
> file extension anyway (and its default list of extensions with which
> ASCII mode should be used is easily changed). Call this code rget.cfm.
> --->
> <!---
> <cfftp connection="movefiles" action="GetFile"
> remotefile="untitled.txt"
> localfile="C:\Inetpub\wwwroot\CFFTP\file_folder\untitled.txt"
> transfermode="binary"
> timeout="30" retrycount="3" stoponerror="no" failifexists="no">
> --->
> <cfftp connection="movefiles" action="GetFile"
> REMOTEFILE="/"
> localfile="C:\Inetpub\wwwroot\CFFTP\file_folder"
> transfermode="binary"
> timeout="30" retrycount="3" stoponerror="no" failifexists="no">
> <!---
> Delete a Local File
> The command to delete a local file is actually a one-liner that's pulled
> out into a separate file for clarity. The file parameter consists of the
> path to the script (set by view.cfm), the directory below it that holds
> these files, and the name of the file. Call this code ldel.cfm.
>
> <cffile action="delete"
> file="#scriptdir#/stuff/#mydel#">
> --->
> <!---
> Close a Remote Connection
> If you don't close the connection, it will tie up resources of two
> computers until the remote server eventually times it out. Call this
> code rclose.cfm.
> --->
>
> <cfftp connection="movefiles" action="close">
>
>
>
> <p>When this page is accesed the text files from &quot;cfftp&quot; are
> tranfered
> to &quot;file_folder&quot;.</p>
> <p><CFFTP CONNECTION=FTP
> USERNAME="anonymous"
> PASSWORD="guest@unknown"
> SERVER="172.17.89.157"
> ACTION="Open"
> STOPONERROR="Yes">
> <CFFTP CONNECTION=FTP
> ACTION="GetCurrentDir"
> STOPONERROR="Yes">
> </p><CFOUTPUT> FTP directory listing of #cfftp.returnvalue#.<p>
> </CFOUTPUT>
>
> <CFOUTPUT>
> Return is #cfftp.returnvalue#
> </CFOUTPUT><BR>
>
> <CFFTP CONNECTION=FTP
> ACTION="ListDir"
> DIRECTORY="//file_folder"
> NAME="ListFiles"
> STOPONERROR="Yes">
>
> <HR>
> <form name="ftpfiles" method="post" action="ftpfiles.cfm">
> <h3>FTP Directory Listing:</h3>
> <cftable query="ListFiles" HTMLTABLE>
> <cfcol header="<B>Name</B>" text="<B>Name:</B> #name#">
> <cfcol header="<B>Path</B>" text="<B>Path:</B> #path#">
> <cfcol header="<B>URL</B>" text="<B>URL:</B> #url#">
> <cfcol header="<B>Length</B>" text="<B>Length:</B> #length#">
> <cfcol header="<B>Date Formted</B>" text="<B>Date Formatted:</B>
> #DateFormat(LastModified)#">
> <cfcol header="<B>IsDirectory</B>" text="<B>IsDirectory:</B> #isdirectory#">
> </cftable>
>
>
> 
______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to