开发者

transferring a remote file to a remote ftp via php

开发者 https://www.devze.com 2023-03-30 04:22 出处:网络
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.

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?


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


Simply:

copy('ftp://user:pass@from.com/file.txt', 'ftp://user:pass@dest.com/file.txt');

The PHP server will consume bandwidth upload and download simultaneously.

0

精彩评论

暂无评论...
验证码 换一张
取 消