How to send all files from a folder via FTP in PHP?

Asked

Viewed 699 times

1

I need to take all files from a local folder and send via FTP to a folder on the server.

Explanation:

I have a folder with images (.jpg) of products that at the time of registering.

And I need to take these images and take them to another server via FTP, so that it would not be functional to select or even make manual the process, with this I need a way via PHP programming that I schedule later in the server cron to run.

Thanks

  • How are you doing? (Code)

1 answer

1

Use http://php.net/manual/en/book.ftp.php

An example of uploading:

<?php
$ftp_server = '<endereço do ftp>';
$ftp_user_name = '<usuario>';
$ftp_user_pass = '<senha>';

//Arquivo de origem
$file = '/pasta/no/servidor/de/origem/imagem.jpg';

//Aonde será salvo
$remote_file = 'pasta/no/servidor/remoto/imagem.jpg';

$conn_id = ftp_connect($ftp_server);

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
    echo "Upload de $file completo\n";
} else {
    echo "Erro ao enviar o $file\n";
}

ftp_close($conn_id);

If you want to send all of a folder you can use opendir or scanndir or FileSystem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.