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 and send it to an offsite server.
您将用它做什么? 好了,您可以设置一个cron来并将其发送到非现场服务器。
翻译自:
php用ftp协议传送文件