使用 CURL 通过 SFTP 删除文件
Delete file over SFTP using CURL
我想用curl删除文件
我正在使用 SFTP,下面是我正在使用的代码。它对我不起作用
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, "sftp://use:@101.101.101.101/");
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($ch, CURLOPT_PORT, 51402);
curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE, '/home/web/.ssh/id_rsa');
curl_setopt($ch, CURLOPT_SSH_PUBLIC_KEYFILE, '/home/web/.ssh/id_rsa.pub');
curl_setopt($ch, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PUBLICKEY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_QUOTE, array("DELE /dispatch/confirm/W00027478.csv"));
$result = curl_exec($ch);
$error_no = curl_errno($ch);
curl_close($ch);
if ($error_no == 0) {
echo "Delete File $filename<br>";
} else {
echo "File Not Delete $filename<br>";
}
DELE 不是有效的 SFTP 命令,我认为您正在寻找命令 rm
,它应该类似于:
curl_setopt($ch, CURLOPT_QUOTE, array("rm ".escapeshellarg("/dispatch/confirm/W00027478.csv"));
下次遇到 curl 问题时,启用 CURLOPT_VERBOSE,然后执行
var_dump(curl_errno($ch),curl_error($ch));
和 post VERBOSE 日志和 curl_errno() 的输出以及 curl_error()
的输出
我想用curl删除文件
我正在使用 SFTP,下面是我正在使用的代码。它对我不起作用
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, "sftp://use:@101.101.101.101/");
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($ch, CURLOPT_PORT, 51402);
curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE, '/home/web/.ssh/id_rsa');
curl_setopt($ch, CURLOPT_SSH_PUBLIC_KEYFILE, '/home/web/.ssh/id_rsa.pub');
curl_setopt($ch, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PUBLICKEY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_QUOTE, array("DELE /dispatch/confirm/W00027478.csv"));
$result = curl_exec($ch);
$error_no = curl_errno($ch);
curl_close($ch);
if ($error_no == 0) {
echo "Delete File $filename<br>";
} else {
echo "File Not Delete $filename<br>";
}
DELE 不是有效的 SFTP 命令,我认为您正在寻找命令 rm
,它应该类似于:
curl_setopt($ch, CURLOPT_QUOTE, array("rm ".escapeshellarg("/dispatch/confirm/W00027478.csv"));
下次遇到 curl 问题时,启用 CURLOPT_VERBOSE,然后执行
var_dump(curl_errno($ch),curl_error($ch));
和 post VERBOSE 日志和 curl_errno() 的输出以及 curl_error()
的输出