Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ftp_fput vs ftp_put?

Tags:

php

ftp

In PHP and its manual, i can't clearly find the difference between ftp_fput vs ftp_put.

  • ftp_fput
  • ftp_put

Can anyone clarify these two methods please?

like image 211
夏期劇場 Avatar asked Oct 02 '12 07:10

夏期劇場


3 Answers

ftp_fput() expects an open resource and ftp_put() just use a (local) filename

ftp_put($foo, $bar, $filename, $baz);
ftp_fput($foo, $bar, fopen($filename, 'r+b'), $baz);
like image 67
KingCrunch Avatar answered Oct 05 '22 01:10

KingCrunch


  • ftp_fput
    • "Uploads from an open file to the FTP server"
  • ftp_put
    • "Uploads a file to the FTP server"

More specifically, ftp_fput takes a resource created with fopen as the file to upload where as ftp_put takes the filename as a string.

like image 24
Explosion Pills Avatar answered Oct 04 '22 23:10

Explosion Pills


ftp_put requires a filename, while ftp_fput takes a file handle:

ftp_put($conn_id, "remote_file_name.txt", "local_file_name.txt", FTP_ASCII);

but

$file_handle = fopen("local_file_name.txt", "r");
ftp_fput($conn_id, "remote_file_name.txt", $file_handle, FTP_ASCII);
like image 29
Mark Avatar answered Oct 04 '22 23:10

Mark