PHP uses ftp function to implement simple upload function

WBOY
Release: 2016-07-25 09:04:37
Original
885 people have browsed it
  1. /**

  2. ftp upload file
  3. link: bbs.it-home.org
  4. date: 2013/2/25
  5. */
  6. $ftp_server = "192.168.8.8";
  7. $ftp_user = "test123";
  8. $ftp_pass = "yourpassword";

  9. // set up a connection or die

  10. $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

  11. $login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

  12. if ((!$conn_id) || (!$login_result)) {

  13. echo "FTP connection has failed!";
  14. echo "Attempted to connect to $ftp_server for user $ftp_user_name";
  15. exit;
  16. } else {
  17. echo "Connected to $ftp_server, for user $ftp_user_name";
  18. }

  19. // try to login

  20. $filename=date('Ymd').".xml";
  21. $source_file="/var/mydata/".$filename; //源地址
  22. echo $source_file;
  23. $destination_file="/admin/ftplog/".$filename; //目标地址
  24. $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY) or die("Couldn't connect to $ftp_server");
  25. ftp_quit($conn_id);

  26. if (!$upload) {

  27. echo "FTP upload has failed!";
  28. } else {
  29. echo "Uploaded $source_file to $ftp_server as $destination_file";
  30. }
  31. ftp_close($conn_id);
  32. ?>

复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template