如何使用 cfscript 移除/删除远程 FTP 文件?
How do you remove / delete a remote FTP file using cfscript?
到目前为止,我的脚本可以打开远程 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() 函数的资源。
哦 - 我的问题是一个错字:
deleteRemoteFile = ftpService.remove(
connection = variables.ftpConnectionName,
remoteFile = fileList.name
);// had } instead of )
我仍将其保留为 ftpService()
的资源
到目前为止,我的脚本可以打开远程 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() 函数的资源。
哦 - 我的问题是一个错字:
deleteRemoteFile = ftpService.remove(
connection = variables.ftpConnectionName,
remoteFile = fileList.name
);// had } instead of )
我仍将其保留为 ftpService()
的资源