I have a PHP script which I use to rename a file on the FTP server root.
I need to change this to rename the file in a directory on the FTP root.
current working
rename file in root to despgoods.csv
desired working
rename file in root/despgoods/despgoods.csv
My PHP script is:
$ftp_server = "ftp.ftpserver.co.za";
$conn_id = ftp_connect($ftp_server);
$ftp_user_name = "username";
$ftp_user_pass = "password";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$targetname = "DespGoods.csv";
$contents = ftp_nlist($conn_id, '');
if (!$contents) {
echo 'No Files Present on Server: <br/> ';
echo mysql_error();
die;
}
$filename = $contents[0];
if ($filename == "despGoods.csv") {
echo 'DespGoods already exists, no need to rename: <br/> ';
echo mysql_error();
} else {
ftp_rename($conn_id, $filename, $targetname);
ftp_close($conn_id);
echo "1 available file renamed to DespGoods.csv <br>";
}
Thanks in advance, I appreciate the help as always,
Regards,
Ryan
http://php.net/manual/en/function.ftp-chdir.php
or
P.S. What
mysql_error()doing in your code?