-1

Hello serve all friends

Friends, does anyone know how to download files from ftp to php?

For example

test/file.zip

How to download this file with ftp

emn
  • 1
  • 4
  • For example, the link test.com/file.zip Become test.com/45 – emn Dec 09 '21 at 17:32
  • How to download a file with ftp For example test / file.zip How to download this file with ftp – emn Dec 09 '21 at 18:08
  • You already had code to just do that but now you removed it. It was a good start. Was there an error when you ran it? Now your question is so generic it's probably answerable by just finding a tutorial – ADyson Dec 09 '21 at 18:22

1 Answers1

-1

First you need to go to your php.ini file and add this --enable-ftp

Second Set Up connection and Download your file

<?php

$ftp_server = "ftp.example.com";

// set up a connection or die
$ftp = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// define some variables
$local_file = 'local.zip';
$server_file = 'server.zip';

// set up basic connection

// login with username and password
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);

// try to download $server_file and save to $local_file
if (ftp_get($ftp, $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($ftp);

?>
Mostafa Ezzat
  • 29
  • 1
  • 11
  • 2
    This is pretty much the code the OP had in the [original posting](https://stackoverflow.com/revisions/70293884/1). So I assume that this is not what s/he is after. As the question currently stands, it's bit pointless to try to answer it, as it's unclear what OP wants. + Moreover, why two `ftp_connect`? And without `ftp_pasv` the code will likely fail in most environments. – Martin Prikryl Dec 10 '21 at 07:10
  • Oh sorry I didn't even see the revision part, maybe he needs to add `--enable-ftp` , if it didn't work with him i'll delete the answer – Mostafa Ezzat Dec 10 '21 at 08:58