提问人:nechmi bader 提问时间:11/7/2023 最后编辑:nechmi bader 更新时间:11/7/2023 访问量:58
将FTP转换为SFTP (CURL / PHP)
convert FTP to SFTP (CURL / PHP)
问:
我有一个PHP应用程序,适用于FTP协议。 我想从 FTP 切换到 SFTP。
我的代码适用于 ftp,如果我安装其他库以继续使用 sftp/curl
private function send($fileName)
{
$ancvSageConf = sfConfig::get("ap_reports");
$remoteName = $ancvSageConf["ftpDir"] . basename($fileName);
$timeout = $ancvSageConf["ftpTimeout"];
$fp = fopen($fileName, 'r');
$this->curl = curl_init("ftp://" . $ancvSageConf["ftpAddress"] . "/" . $remoteName);
curl_setopt($this->curl, CURLOPT_PORT, $ancvSageConf["ftpPort"]);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($this->curl, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
curl_setopt($this->curl, CURLOPT_VERBOSE, TRUE);
curl_setopt($this->curl, CURLOPT_USERPWD, $ancvSageConf["ftpUser"] . ":" . $ancvSageConf["ftpPass"]);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->curl, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($this->curl, CURLOPT_FTP_USE_EPSV, TRUE);
curl_setopt($this->curl, CURLOPT_UPLOAD, 1);
curl_setopt($this->curl, CURLOPT_INFILE, $fp);
curl_setopt($this->curl, CURLOPT_INFILESIZE, filesize($fileName));
curl_setopt($this->curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($this->curl, CURLOPT_FTP_USE_EPSV, false);
curl_exec($this->curl);
$errorNo = curl_errno($this->curl);
fclose($fp);
curl_close($this->curl);
}
我应该在我的代码中更改什么以使用 SFTP 而不是 FTP?
我无法测试我的代码的问题,服务器只能在生产中访问
谢谢。
答: 暂无答案
评论
phpseclib