在 PHP 中的两个远程 FTP 服务器之间传输文件 [英] Transfer files between two remote FTP servers in PHP

查看:30
本文介绍了在 PHP 中的两个远程 FTP 服务器之间传输文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我知道这是一个重复的主题,但是我发现的另一个帖子对我的情况没有用,所以我决定创建一个新的.

First of all, I know that this a duplicate topic, but the other post that I found were not useful for my situation, so I decided to create a new one.

我想要完成的是从一台 FTP 服务器获取文件并将其上传到另一台 FTP 服务器.

What I'm trying to accomplish is to get a file from one FTP server and upload it to another FTP server.

我正在使用此代码:

$ftp_server = "ftp_server";
$ftp_user_name = 'ftp_username' ;
$ftp_user_pass = 'ftp_pass' ;
$localDir = "full/path/";
$serverDir = "full/path/";

$conn_id = ftp_connect($ftp_server);

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

if (ftp_get($conn_id, $localDir, $serverDir, FTP_BINARY)) {
    // ftp_fput($conn_id, $file, $fp, FTP_ASCII))
}

我遇到的问题是当你使用 ftp_put 命令时,它需要一个本地文件,但是这个文件不在我的电脑上,所以我无法将它上传到另一个 ftp.

The problem that I have is when you use ftp_put command, it requires a local file, but this file it's not on my computer, so I can't upload it to the other ftp.

有没有办法使用 ftp_put 将我刚刚通过 ftp_get 函数获得的文件上传到另一台服务器?无需先在 PC 上下载?

Is there a way to upload the file that I just got with ftp_get function into another server using ftp_put? Without the need to download it first on your PC?

谢谢!

推荐答案

ftp_getftp_put 都只能操作文件,不能操作文件夹.

Both ftp_get and ftp_put can operate with files only, not folders.

使用 ftp_get 将文件从第一台服务器下载到本地临时文件夹/文件.然后使用ftp_put将临时文件上传到第二台服务器.

Use ftp_get to download a file from the first server to a local temporary folder/file. And then use ftp_put to upload the temporary file to the second server.

如果您想避免使用临时文件,可以使用 ftp_fget 将文件下载到内存,然后使用 ftp_fput 重新上传到第二个服务器.

If you want to avoid using a temporary file, you can download the file to memory using ftp_fget and re-upload to the second server using ftp_fput.

这篇关于在 PHP 中的两个远程 FTP 服务器之间传输文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆