我使用 Contribute 的 File Deployer 工具已经有一段时间了,在我们更换了将文件推送到的服务器之前,它一直运行良好。推送文件本身工作正常,权限和所有。但主要功能的一部分是它扫描您的文件被推送到的目录,如果它不存在,那么它会创建所述目录。
到目前为止,工具的这一部分总是失败。被推送文件的完整路径的格式是\\\x.x.x.x\sync$\path/to/folder
(混合斜杠总是有效的。)
这是在带有 ColdFusion 8 的 Windows XP sp3 上。
<cftry>
<cfinvoke method="MakeSurePathExists" path="#serverPathToPush##siteRelative#">
<cfcatch type="any">
<cfthrow errorcode="NoLiveServerAccess" message="Can not access or do not have sufficient permissions to write to: #serverPathToPush##siteRelative#">
<cflog application="yes" text="Can not access or do not have sufficient permissions to write to: #serverPathToPush##siteRelative#" file="Filedeployer" />
</cfcatch>
</cftry>
<cffile action="copy" source="#settings.stagingFileSystemPath & siteRelative#" destination="#serverPathToPush##siteRelative#">
<!--- touch the file so it gets the current date, so the browser will pull down the new one when previewed --->
<cffile action="append" file="#serverPathToPush##siteRelative#" output="">
<!--- This function checks if the directory exist of the given file.
If it doesn't, it tries to build path. If it fails, the function throws --->
<cffunction name="MakeSurePathExists">
<cfargument name="path" type="string" required="true">
<cfset createList = ArrayNew(1)>
<cfinvoke method="RemoveLastFileFromPath" path="#path#" returnvariable="parentdir">
<cfloop condition="not DirectoryExists( parentDir ) and Len( parentDir ) gt 0 ">
<cfset temp = ArrayAppend( createList, parentDir ) >
<cfinvoke method="RemoveLastFileFromPath" path="parentdir" returnvariable="parentdir">
</cfloop>
<cfloop from="#ArrayLen( createList )#" to="1" step="-1" index="index">
<cfdirectory action="create" directory="#createList[index]#">
</cfloop>
</cffunction>
<cfscript>
function RemoveLastFileFromPath( path )
{
rpath = Reverse( path ) ;
idx2 = Find( "\", rpath ) ;
idx = Find( "/", rpath ) ;
if( idx2 is not "0" and idx2 lt idx )
idx = idx2 ;
if( idx is not "0" ) {
rpath = Right( rpath, Len(rpath) - idx ) ;
return Reverse( rpath ) ;
}
return "" ;
}
</cfscript>
我得到的友好错误是:
无法访问或没有足够的权限写入:\xxxx\sync$\ path/to/folder/the-file.cfm
CFDUMP 的错误:
此错误的最可能原因是您的文件系统上已存在 \xxxx\sync$\ path/to/folder/。cfdirectory action="create" 期间发生异常。
我知道共享 URL 末尾和相对路径之间的空格。同样,这以前不是问题,我不确定现在是否存在。