使用cfscript如何删除远程FTP文件?

3

到目前为止,我的脚本可以成功地打开一个远程FTP连接、更改目录并下载文件。接下来的两个步骤是,在文件完全下载后删除远程文件,然后关闭连接。ACF文档(和cfdocs)似乎对此有很少的信息。以下是我目前的代码:

ftpConnection = ftpService.open(
  action = 'open', 
  connection = variables.ftpConnectionName, 
  server = variables.ftpServerName, 
  username = '***************', 
  password = '***************', 
  secure='true');

if( ftpConnection.getPrefix().succeeded ){
    fileList = ftpService.listdir(directory = variables.ftpPath, connection= variables.ftpConnectionName, name='pendingFiles', stopOnError='true').getResult();
      if( fileList.recordCount ){
        changeFtpConnectionDir = ftpService.changeDir(
        connection = variables.ftpConnectionName,
        directory = variables.ftpPath);


      getFtpConnection = ftpService.getFile(
        connection = variables.ftpConnectionName,
        remoteFile = fileList.name,
        localFile = local.localPath & fileList.name,
        failIfExists = false,
        timeout = 3000
      );

      deleteRemoteFile = ftpService.remove(
        connection = variables.ftpConnectionName,
        remoteFile = fileList.name
      };

      closeFtp = ftpService.close(
          connection = variables.ftpConnectionName
      );

   };
};

在remoteFile = fileList.name处抛出错误。由于我已经更改了目录,我认为不需要在这里输入完整路径。

我将整个脚本放在这里,因为似乎没有太多关于使用较新的ftpServer()函数的资源。


2
始终包含错误信息的提示。如果解析器未能识别括号问题,那将令人惊讶。 - Alex
1个回答

4

天哪 - 我的问题是一个拼写错误:

deleteRemoteFile = ftpService.remove(
    connection = variables.ftpConnectionName,
    remoteFile = fileList.name
  );// had } instead of )

我仍然会将其保留为ftpService()的资源。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接