/ Published in: PHP
URL: http://www.jonasjohn.de/snippets/php/ftp-example.htm
Shows how to upload a single file to a FTP server.
Expand |
Embed | Plain Text
// FTP access parameters: $host = 'ftp.example.org'; $usr = 'example_user'; $pwd = 'example_password'; // file to upload: $local_file = './example.txt'; $ftp_path = '/data/example.txt'; // connect to FTP server (port 21) // send access parameters // turn on passive mode transfers (some servers need this) // ftp_pasv ($conn_id, true); // perform file upload // check upload status: print "\n"; /* ** Chmod the file (just as example) */ // If you are using PHP4 then you need to use this code: // (because the "ftp_chmod" command is just available in PHP5+) function ftp_chmod($ftp_stream, $mode, $filename){ } } // try to chmod the new file to 666 (writeable) if (ftp_chmod($conn_id, 0666, $ftp_path) !== false) { } else { print "could not chmod $file\n"; } // close the FTP stream
Comments
Subscribe to comments
You need to login to post a comment.

excellent... this is the one for which i'm searching the whole internet !!! thanks a tonne
haven't tested this but according to the link provided line 23 has a typo
// check upload status: print (!$upload) ? 'Cannot upload' : 'Upload complete'; print "\n";
it just missing a ?
Yes, it's missing a ? on line 23...I just don't know how to edit the snippet. :(
Fixed the typo, thanks!