php使用ftp函數實現簡單上傳功能

來源:互聯網
上載者:User
  1. /**

  2. ftp上傳檔案
  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. ?>

複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.