首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cfftp :远程复制和移动文件?

cfftp :远程复制和移动文件?
EN

Stack Overflow用户
提问于 2011-01-16 11:52:18
回答 3查看 4.2K关注 0票数 0

我需要将文件从一个文件夹复制到同一个sftp服务器上的另一个文件夹。我的代码当前将文件复制到本地并重新上载。

代码语言:javascript
复制
<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做到这一点?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-01-19 21:17:43

已发现ftp protocol不提供将文件远程复制到另一个文件夹并保留原始文件的方法。这使得coldfusion无法提供解决方案。另一方面,移动文件可以通过重命名来完成。请参阅其他答案和对原始问题的评论。

票数 0
EN

Stack Overflow用户

发布于 2011-01-17 00:22:16

使用CFFTP,您可以重命名(检查docs),这应该可以解决您的问题

票数 0
EN

Stack Overflow用户

发布于 2013-05-23 18:16:53

显示文件目录的代码:

代码语言:javascript
复制
    <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>

获取文件并将其保存在我们的系统中的代码如果文件存在,则替换:

代码语言:javascript
复制
    <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" />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4703694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档