php用ftp协议传送文件_使用PHP通过FTP发送文件

php用ftp协议传送文件

Sending files to a server via FTP is an essential ability of any web developer or designer. Of course, we all use glossy FTP clients like WS_FTP and FireFTP, but what about FTP automation? You can use PHP to FTP files from one server to another. Let me show you how.

通过FTP将文件发送到服务器是任何Web开发人员或设计人员的基本能力。 当然,我们都使用像WS_FTP和FireFTP这样的有光泽的FTP客户端,但是FTP自动化又如何呢? 您可以使用PHP将FTP文件从一台服务器传输到另一台服务器。 让我告诉你怎么做。

PHP (The PHP)


$connection = ftp_connect($server);

$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);

if (!$connection || !$login) { die('Connection attempt failed!'); }

$upload = ftp_put($connection, $dest, $source, $mode);

if (!$upload) { echo 'FTP upload failed!'; }

ftp_close($connection); 


Obviously, the first task is to connect to the other server. Once the connection is created, you pass the login credentials. Once you're logged in, you can use the ftp_put() function to send the file. That's it!

显然,第一个任务是连接到其他服务器。 创建连接后,您将传递登录凭据。 登录后,可以使用ftp_put()函数发送文件。 而已!

What would you use this for? Well, you could set up a cron to create a database backup and send it to an offsite server.

您将用它做什么? 好了,您可以设置一个cron来创建数据库备份并将其发送到非现场服务器。

翻译自: https://davidwalsh.name/send-files-ftp-php

php用ftp协议传送文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值