Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to upload files from FTP to FTP using PHP

Tags:

Here is my prob in Brief.

I know how to upload a file to server using FTP with programming language PHP.

But is that possible to get files from another server to our server using PHP with

having the FTP Username and Password

Thanks n advance...

Fero

like image 812
Fero Avatar asked Nov 06 '09 14:11

Fero


2 Answers

Technically, the FTP protocol allows for server-to-server transfers, called FXP. This feature is disabled by default on most FTP servers, though, for security reasons, so you would need to be able to verify/enable it before it would work.

If it is enabled, you should just need to script the FXP commands and everything should work fine.

like image 44
Guy Starbuck Avatar answered Oct 20 '22 00:10

Guy Starbuck


Yes, you can fetch files from FTP using PHP - using ftp_get.

The following snippet is from the documentation:

$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";
}
like image 137
Dominic Rodger Avatar answered Oct 20 '22 01:10

Dominic Rodger