到目前为止,我的脚本可以成功地打开一个远程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()函数的资源。