Md Nazrul Islam
Md Nazrul Islam

Reputation: 373

Append content of a file a another file on the FTP server in PHP server

Is this function in php that I can use for transfer a file remotely from one server to another? Such as

ftp_append( 
  resource $ftp, 
  string $remote_file, 
  string $local_file
  [, int $mode = FTP_IMAGE ]
)

Upvotes: 0

Views: 694

Answers (2)

Foobar
Foobar

Reputation: 313

ftp_append appends to a file on the FTP server and does create it if it does not exist.

If you need to add to a file repeatedly (e.g. a log) on the ftp server without having to worry about whether it was deleted or may not be overwritten and do not want to write the whole get-append-put logic yourself, you can use this function.

Upvotes: 0

Stasa Stanisic
Stasa Stanisic

Reputation: 34

You can use file_get_contents to get contents of a file, and then append it with file_put_contents:

<?php

$username = "user";
$password = "pass";
$host = "localhost";
$file_from = "file_from.txt"
$file_to = "file_to.txt";

$file_from_contents = file_get_contents($file_from);

$result = file_put_contents("ftp://$username:$password@host/$file_to", $file_from_contents, FILE_APPEND);

if($result === false) {
echo "An error occured";
}

Upvotes: 1

Related Questions