tags:

views:

469

answers:

2

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?

Thanks!

+1  A: 

PHP FTP Example

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.

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

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.

ryanday
I know how to deal with $_POST and $_SESSION arrays, I am just not familiar with creating files at all in PHP or doing FTP with PHP. I will check out the links you provided. Thanks!
John Isaacks
I was able to tweak the example you posted to get it to work! However fputcsv is only PHP>=5 I am using 4. I will start a new question asking how to make the file since this question was more towards how to FTP and I got that working now. Thanks!
John Isaacks
I'm glad it worked! Take a look at fprintf() as well for putting '\t' between your info elements as you're writing the file.
ryanday
I am not sending CC numbers of course, but I am going to be sending address+zip because they are going to be mailing out the products. What is this HTTPS connection you are talking about?
John Isaacks
Also my server sending the FTP file would be https, but their's receiving it I don't think is. This is what they said to do though.
John Isaacks
+3  A: 

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:

ftp://user:[email protected]/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.

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

Ionuț G. Stan
Thanks for the info, I really want to move to PHP5!!
John Isaacks