我需要在同一个sftp服务器上将文件从一个文件夹复制到另一个文件夹。我的代码目前在本地复制文件并重新上传。
<cfftp
action = "open"
username = "#APPLICATION.intxml.SFTPUSERNAME#"
password = "#APPLICATION.intxml.SFTPPASSWORD#"
connection = "sftpcon"
server = "#APPLICATION.intxml.SFTPADDRESS#"
port = "#APPLICATION.intxml.SFTPPORT#"
timeout = "#APPLICATION.pageTimeout#"
secure = "#sftp#"/>
<cfif cfftp.succeeded>
<cfftp action = "LISTDIR" stopOnError = "No" name = "ListFiles" directory = "/#sfolder#" connection = "sftpcon"/>
<cfloop query=getFiles>
<cfftp action = "GETFILE"
stopOnError = "Yes"
name = "theFile"
transferMode = "binary"
timeout = 3600
retrycount = 10
remoteFile = "#sfolder##name#"
localFile = "#dfolder#/#name#"
failIfExists = "no"
connection = "sftpcon">
<cfftp action = "PUTFILE"
stopOnError = "Yes"
name = "theFile"
transferMode = "binary"
timeout = 3600
retrycount = 10
localfile = "#sfolder##name#"
remoteFile = "#dfolder#/#name#"
failIfExists = "no"
connection = "sftpcon">
</cfloop>
</cfif>
<cfftp action = "close"
connection = "sftpcon"
stopOnError = "Yes">
使用coldfusion有更好的方法吗?
答案 0 :(得分:0)
使用CFFTP,你可以做一个RENAME(查看docs)来解决你的问题
答案 1 :(得分:0)
发现ftp protocol没有提供将文件远程复制到另一个文件夹并保留原始文件的方法。这阻止了coldfusion提供解决方案。另一方面,移动文件可以通过重命名来完成。请参阅原始问题的其他答案和评论。
答案 2 :(得分:0)
显示文件目录的代码:
<cfftp
username= "username"
password= "password"
port= "22"
server= "hostofyousystem"
secure= "yes"
name= "ftpconnection"
action= "listdir"
directory= "/" />
<cfdump var="#ftpconnection#" />
<cfoutput query="ftpconnection">
#path#<br/>
</cfoutput>
获取文件的代码,如果文件存在,则将其保存在我们的系统中,然后替换:
<cfftp
username= "username"
password= "password"
port= "22"
server= "hostofyousystem"
secure= "yes"
action= "getFile"
remotefile= "/myfile.csv"
localfile= "D:/web/files/Data/thisfile.csv"
failIfExists="no" />