我想通过PHP通过FTP创建目录。我遇到的问题与Connection to secure FTP Server from PHP
所以,我将尝试使用cURL。
这是我所做的:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "ftp://example.com/NEWDIR");
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_setopt($ch, CURLOPT_FTP_CREATE_MISSING_DIRS, CURLFTP_CREATE_DIR_RETRY);
$res = curl_exec($ch); //bool(false)
curl_close($ch);
if($res === true){
echo "Folder have been created";
}else{
echo "Error";
}
我总是得到Error
输出。
希望这对您有帮助
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "ftp://xxxx.com/public_html/tested/");
curl_setopt($ch, CURLOPT_PORT, 21);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_FTP_CREATE_MISSING_DIRS, TRUE);
curl_exec($ch);
curl_close($ch);