Hi all,
I am trying to connect to an FTP server and download a file. The problem I am having is I get the follwoing error:
Connected to vintageandclassic.com, for user redundget
Warning: ftp_get(LGW.CSV) [function.ftp-get]: failed to open stream: Permission denied in /var/www/vhosts/mydomaincom/httpdocs/lgw/vintageftp.php on line 29
Warning: ftp_get() [function.ftp-get]: Error opening LGW.CSV in /var/www/vhosts/mydomain.com/httpdocs/lgw/vintageftp.php on line 29
Can anyone see what I am doing wrong. Many thanks in advance.
$ftp_user_name = 'username';
$ftp_user_pass = 'password';
// set up basic connection
$ftp_server = 'mydomain.com';
$conn_id = ftp_connect($ftp_server);
$local_file = 'LGW.CSV';
$server_file = 'LGW.CSV';
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "Ftp connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
die;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// download the file
// try to download $server_file and save to $local_file
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 FTP stream
ftp_close($conn_id);