Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search after a File

Status
Not open for further replies.

innu

Programmer
Jun 13, 2001
40
AT
Hi,

My problem is:

I get a file through FTP, but I've to look up, if the File exists (.csv-file).

How can I proove if the file exists on the server?

thx,
yours Innu
 
<cfdirectory action=&quot;list&quot; directory=&quot;c:\temp&quot; name=&quot;dirListing&quot;>, will return the contents of the dirctory where you are looking for existance of the file

then you can use this:
<cfloop query=&quot;listing&quot;>
<cfif name EQ &quot;fileYouLookingFor.csv&quot;>
<cfset foundIt = &quot;true&quot;>
</cfif>
</cfloop>


<cfif foundIt>
your file exist
</cfif> Sylvano
dsylvano@hotmail.com

&quot;every and each day when I learn something new is a small victory...&quot;
 
If you only have FTP access to the server, you could do it this way.

Save the code below and put into a file named FtpFileExists.cfm.

[COLOR=666666]<!--- Start FtpFileExists.cfm --->[/color]
[COLOR=666666]<!--- This file returns a boolean value as REQUEST.FtpFileExists --->[/color]
<CFPARAM NAME=&quot;ATTRIBUTES.port&quot; DEFAULT=&quot;21&quot;>

<CFIF NOT IsDefined(&quot;ATTRIBUTES.username&quot;)
OR NOT IsDefined(&quot;ATTRIBUTES.password&quot;)
OR NOT IsDefined(&quot;ATTRIBUTES.server&quot;)
OR NOT IsDefined(&quot;ATTRIBUTES.folder&quot;)
OR NOT IsDefined(&quot;ATTRIBUTES.filename&quot;)>

You must define the following attributes in this CF_FtpFileExists tag:
[COLOR=000080]<UL>[/color]
[COLOR=000080]<LI>[/color]USERNAME[COLOR=000080]</LI>[/color]
[COLOR=000080]<LI>[/color]PASSWORD[COLOR=000080]</LI>[/color]
[COLOR=000080]<LI>[/color]SERVER[COLOR=000080]</LI>[/color]
[COLOR=000080]<LI>[/color]FILENAME[COLOR=000080]</LI>[/color]
[COLOR=000080]</UL>[/color]
<CFABORT>
</CFIF>

<CFSET REQUEST.FtpFileExists = 0>
[COLOR=666666]<!---Open the FTP connection--->[/color]
<CFFTP ACTION=&quot;OPEN&quot;
SERVER=&quot;#attributes.server#&quot;
USERNAME=&quot;#attributes.username#&quot;
PASSWORD=&quot;#attributes.password#&quot;
PORT=&quot;#attributes.port#&quot;
TIMEOUT=&quot;500&quot;
STOPONERROR=&quot;Yes&quot;
CONNECTION=&quot;Request.ConnectionName&quot;
PASSIVE=&quot;yes&quot;>


<CFFTP ACTION=&quot;ListDir&quot;
CONNECTION=&quot;Request.ConnectionName&quot;
NAME=&quot;ContentList&quot;
DIRECTORY=&quot;#Attributes.Folder#&quot;>


<CFOUTPUT QUERY=&quot;ContentList&quot;>
<CFIF NOT IsDirectory
AND ContentList.name IS ATTRIBUTES.filename>

<CFSET REQUEST.FtpFileExists = 1>
</CFIF>
</CFOUTPUT>

<CFFTP ACTION=&quot;close&quot; CONNECTION=&quot;Request.ConnectionName&quot;>
[COLOR=666666]<!--- END FtpFileExists.cfm --->[/color]


Then you'd call it using this method
<CF_FtpFileExists
USERNAME=&quot;username&quot;
PASSWORD=&quot;password&quot;
SERVER=&quot;server&quot;
FOLDER=&quot;/folder/list/to/file&quot;
FILENAME=&quot;filename&quot;>


<CFIF REQUEST.FtpFileExists>
The File Exists
<CFELSE>
The file doesn't exists
</CFIF>

This tag came with help from:
- tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top