我需要编写一个PHP脚本,从ftp服务器(ftp.example.com)下载文件(master.csv)并准备处理和上传。我尝试了很多次,但我的代码不好,我是PHP的新手。我该怎么做呢?
<?php
///vars
$local_file = 'xmitpart2.csv';
$server_file = 'master.csv';
$ftp_server="ftp.example.com";
$ftp_user="username";
$ftp_pass="paswd";
//connect to server
$conn_id = ftp_connect($ftp_server);
// login to ftp
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
//download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_ASCII))
{
echo "Holy Crap Finally!\n";
}
else
{
echo "Of Course.\n";
//WRONGO DIE DIE DIE
die;
}
// close the connection
ftp_close($conn_id);