Skip to content

Instantly share code, notes, and snippets.

@wp-kitten
Created April 25, 2016 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wp-kitten/cbb3b0572a640b602fc5e3975f74009d to your computer and use it in GitHub Desktop.
Save wp-kitten/cbb3b0572a640b602fc5e3975f74009d to your computer and use it in GitHub Desktop.
Get file from remote password protected ftp url
// define some variables
$local_file = 'local.zip';
$server_file = 'server.zip';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
} else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment