Help moving a .zip file to an ftp server please?


I have a .zip file and a .csv file that I need to send to an ftp server on a daily basis. Can anyone tell me how I would go about setting that up please?

Thansk for any help in advance.

Is this a general question on how to use ftp or a question how to do it in php scripting language from your website to another server?

sorry for not being very clear in my initial question. I have a .zip file and a .csv file that sit on my webserver which I need to automatically send to another ftp server at a set time every day.

Can anyone give me some pointers as to how to go about setting this process up?

Thanks in advance.


Well that was useful.

JayP is semi right, Cron would take care of the once a day thing but you need to look into finding a FTP class or reading up on ftp with php (Google) .

Well they did just say pointers ;D
It doesn’t sound like PHP is actually involved, other than the forum we’re in!

Well it is if the op wants to move files from their server to an FTP server which is remote. Cron is only a timer which acts as a trigger. It won’t move the files.

Cron can however trigger a php script which can instruct php to move the files.

Or, perhaps more sensibly, trigger an FTP application

Why not use PHP FTP functions

$file = 'path_and_file_to_send';
$remote_file = 'name_of_file_on_receiving_server';
$conn_id = ftp_connect('ftpserveraddress');
$login_result = ftp_login($conn_id, 'username', 'password');
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
   echo "File successfully uploaded to server.<br /><br />";
   echo "There was a problem uploading file to server<br /><br />";

Such as? - Please name one and how to use it.

The ‘ftp’ command seems like a solid start! :wink:

Just makes more sense to me to use the native FTP application for something to basic than to run a PHP script to do the same thing!

Not all servers have it though - thats the problem and why we’re suggesting the use of phps own ftp functions :wink:

Let’s be honest, I think the OP hates us anyway

??? - Might hate you for your one word replies and stuff but the rest of us have actually tried to help.

My relevant one-word answer that would point them in the right direction or…? Sigh. Why be so uptight on a damn forum; y’asked me to name an FTP application like you’ve never heard of it before, just to be awkward eh. The chances of the host not having it is surely on par with the chances of the PHP FTP extension not being installed so stop being difficult :wink: Please calm with the blunt attitude because it appears you’re stressing me out!

Curious, since it hasn’t been asked nor stated:
What is the relationship between Server A (SA) and Server B (SB)? Meaning not just the physical/scripting but also the people. - The point being, is there a reason why SB cannot have a script to get the files from SA. rather than SA trying to upload?

Also (old but still relative) might look at #5 here REQEST : Upload a file to another remote server - Codewalkers

@ litebearer

no reason, its equally possible to initiate the transfer from either side, but normally you only have control over one side of the equation. Take for example an XML feed of real estate properties, a third party site may give you FTP access to a certain directory to upload your XML file into. You would have no way of installing a script on their server to fetch the file, but you could install a script on your side to put the file inot the remote directory.

You have 3 options to Transfer Files Via FTP in PHP:

  1. use php ftp functions
  2. use fopen/fwrite
  3. use curl

Depending on your host some of the options could be disabled. However I doubt all them are disabled.

Thanks for all the replies on this!! Appreciate the help.
I will look into CRON once I actually get a php file set up to do this manually. I’m trying the ftp_put option but I’m getting the following error:

Warning: ftp_pasv() expects parameter 1 to be resource, null given in /myfile.php on line 3

Warning: ftp_put() [function.ftp-put]: Ok to send data. in /myfile.php on line 9
There was a problem uploading file to server

Here’s the actual file:

ftp_pasv($resource, true);

$file = 'filename.csv';
$remote_file = 'filename.csv';
$conn_id = ftp_connect('ftpaddress');
$login_result = ftp_login($conn_id, 'myusername', 'mypassword');
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
   echo "File successfully uploaded to server.<br /><br />";
   echo "There was a problem uploading file to server<br /><br />";

Any ideas why, other then I’ve obviously got something wrong somewhere?

When I check the destination ftp server I can see that the script has created a file with the correct name but the file is 0kb!! Any suggestions as to whats wrong with this?