用ftp下载文件替换本地文件

时间:2013-01-25 05:38:42

标签: php ftp

<?php
$local_file = "/home/zzh/Desktop/1.txt";
$server_file = "/var/www/helpdesk/1.txt";
$ftpserver = "xxx.xxx.xxx.xx";
$port = xx;
$conn_id = ftp_connect($ftpserver,$port) or die('can\'t connect to ftp'); 
$ftpname="xxx";
$ftppass = "xxx";
ftp_login($conn_id, $ftpname, $ftppass); 

if (ftp_get($conn_id, $local_file, $server_file, FTP_ASCII)) {
echo "Successfully written to $local_file\n";
} else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
?>

我想用这个php登录ftp服务器下载1.txt来替换桌面上的1.txt,但似乎不起作用,我使用的是ubuntu。需要帮助。

PS。我可以成功连接到ftp。

1 个答案:

答案 0 :(得分:0)

如果是IIRC,它应该取代它。

如果没有,为什么不这样做

if ( file_exists($local_file) ) unlink($local_file)

这将在你的ftp_get程序之前完成。

相关问题