Paraiba
Paraiba

Reputation: 11

transferring a remote file to a remote ftp via php

I am developing a PHP script.
I would like to transfer a remote ZIP file to a remote FTP (I'm the owner of the FTP account) via PHP.

For example:

I have two hosting accounts: a Hostgator shared account and a Hostgator VPS account. I want to run my PHP script on the VPS hosting. I'd like my PHP script to upload this file to the shared hosting account.

Does anyone know a PHP class for this issue?

Upvotes: 1

Views: 3006

Answers (2)

GONZO
GONZO

Reputation: 39

Simply:

copy('ftp://user:[email protected]/file.txt', 'ftp://user:[email protected]/file.txt');

The PHP server will consume bandwidth upload and download simultaneously.

Upvotes: 2

Ed Manet
Ed Manet

Reputation: 3178

From the manual:

<?php
$file = 'somefile.txt';
$remote_file = 'readme.txt';

// 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);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
 echo "successfully uploaded $file\n";
} else {
 echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);
?>

Upvotes: 2

Related Questions