开发者

cfftp : Copy and move file remotely?

I need to copy files from one folder to the another on the same sftp server. My code currently copies the files locally and reuploads them.

<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">

Is there a better way to do this with coldfusion?


With CFFTP you can do a RENAME (check the docs) which should solve your problem


Found out that the ftp protocol does not provide a way to remotely copy a file into another folder and keep the original. That precludes coldfusion from providing a solution. Moving files on the other hand can be done with a rename. See the other answer and comments on the original question.


Code to show directories of files:

    <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>

Code to get file and save it in our system if file exist then replace:

    <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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜