PHP:如何创建文件并将其ftp到另一台服务器?

时间:2021-08-17 15:59:54

We are setting up a drop-ship agreement with a vendor to where we don't have to stock their products we just sell them and they ship them out. To inform them of an order they want us to FTP upload a tab delimited .txt file with the order info to their site. We want to automate this. So given the user/pass for the ftp is there a way to create a TSV.txt file and ftp upload it to their site with PHP?

我们正在与供应商建立一个下船协议,我们不必存储我们刚刚销售的产品并将它们运出。要通知他们他们希望我们FTP的订单,将带有订单信息的制表符分隔的.txt文件上传到他们的网站。我们希望自动化这个。因此,给定ftp的用户/传递是否有办法创建TSV.txt文件并使用PHP将ftp上传到他们的站点?

Thanks!

2 个解决方案

#1


PHP FTP Example

PHP FTP示例

I'm not familiar with your order info of course, but you could create an array of the order information and use fputcsv to create the tab delimited file.

我当然不熟悉您的订单信息,但您可以创建订单信息数组并使用fputcsv创建制表符分隔文件。

Do you need specifics on making the file from $_POST information as well? Or just general function calls to implement the solution?

您是否还需要有关从$ _POST信息制作文件的详细信息?或者只是通用函数调用来实现解决方案?

Edit: Also, is it possible to find another solution then FTP'ing the information? Say, an HTTPS connection or something to their server? If you are sending any recipient information(address, zip, credit card) this could be a security problem.

编辑:此外,是否有可能找到另一种解决方案然后FTP信息?比方说,HTTPS连接或其他东西到他们的服务器?如果您要发送任何收件人信息(地址,邮政编码,信用卡),这可能是一个安全问题。

#2


file_put_contents() in PHP5 or a combination of fopen()/fwrite()/fclose() in PHP4 should do the job. Anyway, you should supply the user and pass inside the FTP URL, like this:

PHP5中的file_put_contents()或PHP4中的fopen()/ fwrite()/ fclose()的组合应该可以完成这项工作。无论如何,你应该提供用户并传递FTP URL,如下所示:

ftp://user:password@example.com/pub/file.txt

If the above don't work, ftp_* functions should solve your problem. Anyway, pay attention to the PHP version they're available in. Some function only work in PHP5 and greater.

如果以上不起作用,ftp_ *函数应该可以解决您的问题。无论如何,请注意它们可用的PHP版本。某些功能仅适用于PHP5及更高版本。

This is the page detailing the FTP stream wrapper in PHP.

这是详细介绍PHP中FTP流包装器的页面。

#1


PHP FTP Example

PHP FTP示例

I'm not familiar with your order info of course, but you could create an array of the order information and use fputcsv to create the tab delimited file.

我当然不熟悉您的订单信息,但您可以创建订单信息数组并使用fputcsv创建制表符分隔文件。

Do you need specifics on making the file from $_POST information as well? Or just general function calls to implement the solution?

您是否还需要有关从$ _POST信息制作文件的详细信息?或者只是通用函数调用来实现解决方案?

Edit: Also, is it possible to find another solution then FTP'ing the information? Say, an HTTPS connection or something to their server? If you are sending any recipient information(address, zip, credit card) this could be a security problem.

编辑:此外,是否有可能找到另一种解决方案然后FTP信息?比方说,HTTPS连接或其他东西到他们的服务器?如果您要发送任何收件人信息(地址,邮政编码,信用卡),这可能是一个安全问题。

#2


file_put_contents() in PHP5 or a combination of fopen()/fwrite()/fclose() in PHP4 should do the job. Anyway, you should supply the user and pass inside the FTP URL, like this:

PHP5中的file_put_contents()或PHP4中的fopen()/ fwrite()/ fclose()的组合应该可以完成这项工作。无论如何,你应该提供用户并传递FTP URL,如下所示:

ftp://user:password@example.com/pub/file.txt

If the above don't work, ftp_* functions should solve your problem. Anyway, pay attention to the PHP version they're available in. Some function only work in PHP5 and greater.

如果以上不起作用,ftp_ *函数应该可以解决您的问题。无论如何,请注意它们可用的PHP版本。某些功能仅适用于PHP5及更高版本。

This is the page detailing the FTP stream wrapper in PHP.

这是详细介绍PHP中FTP流包装器的页面。