- Joined
- Nov 1, 2006
- Messages
- 1,417
- Reaction score
- 25
Hey everyone..I'm trying to download a file onto my server using FTP and PHP. The file I'm trying to download is a .GZ file and for some reason I keep getting the following error
first, my code
next, the error
Any idea what could be causing this? I see the file get created locally like it's trying to download - but it's always 0 bytes in size. I know some of you will say to just use the FTP link instead - but the server is locked to my IP so it must be downloaded locally..
Any help is appriciated!
first, my code
Code:
<?php
$conn_id = ftp_connect("hostname.com");
$login_result = ftp_login($conn_id, "username", "password");
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
exit;
} else {
echo "Connected";
}
// get the file
$local = fopen("file.gz","w");
$result = ftp_fget($conn_id, $local,"home/username/public_html/folder/file.gz", FTP_BINARY);
// check upload status
if (!$result) {
echo "FTP download has failed!";
} else {
echo "Downloaded ";
}
// close the FTP stream
ftp_close($conn_id);
?>
next, the error
Code:
PHP Warning: ftp_fget() [<a href='function.ftp-fget'>function.ftp-fget</a>]: Failed to open file. in /home/username/public_html/folder/file.php on line 14
Any idea what could be causing this? I see the file get created locally like it's trying to download - but it's always 0 bytes in size. I know some of you will say to just use the FTP link instead - but the server is locked to my IP so it must be downloaded locally..
Any help is appriciated!