Laravel使用ftp传输文件

时间:2015-12-22 14:13:11

标签: php laravel ftp file-transfer

我在一个服务器上有一个文件,它位于存储文件夹中。我想通过ftp将此文件传输到外部服务器。

我尝试过使用https://github.com/GrahamCampbell/Laravel-Flysystem

但问题是它只允许我更新和读取文件。因此,如果让我们说test.txt不存在,它将返回Undefined offset:8,我追溯到找不到文件

这是破坏的功能:

$fileName = "test2.txt"
$filePath = "path/to/file/to/transfer/test.txt" 
$this->flysystem->connection('ftp')->write($fileName,$filePath);

服务器2上不存在文件test2.txt

此功能允许我更新文件

$this->flysystem->connection('ftp')->put('test.txt','test');

文件test.txt存在于服务器2上

此外,我正在尝试传输.zip文件,但在txt上进行测试

由于

1 个答案:

答案 0 :(得分:0)

试试这个..

$stream = fopen("path/to/file/to/transfer/test.txt" , 'r+');
$this->flysystem->connection('ftp')->writeStream('uploads/test.txt', $stream);
fclose($stream);
相关问题