Forum Moderators: coopster

Message Too Old, No Replies

ftp multiple files

         

carlsimon510

3:58 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



Hello - I am very new to PHP scripting and need some ftp assistance. Here is what I need to do: remove old backup files from local directory, open connection to ftp site, download all the files in the directory for today's date, then run a restore script for all the files just downloaded.

I have got everything covered except for how to download all the files in a folder. I just read that there is not php function equivalent to mget. The folder name is today's date, such as "2006-08-11", and the files within that folder are named "test1_2006-08-11.tar.bz2", "test2_2006-08-11.tar.bz2", and so on. There are about 75 files total.

Thanks, any help is greatly appreciated.

jatar_k

5:41 pm on Aug 14, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld carlsimon510,

you could just tar gz the whole folder and do it as a single download. You may need to watch for execution time and max size though.

carlsimon510

7:45 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



Thanks for the reply jatar_k, I would guess that I would get a timeout issue, or something since these are mysql database files, and they are quite large. If I just go out and run mget ftp command, it will take about 20 mins to download the files manually as is.

The only answer I could think of was to run a loop for all the file names in a folder, but can't think of how to walk through the folder and check to see which ones I have gotten, and which ones I still need to download.

I just figured downloading multiple files from 1 folder in a php script would be a common issue, with a simple answer.

Thanks, Carl

jatar_k

7:48 pm on Aug 14, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



to be honest I have never had a use for ftp functions in php

I have used php to create a list of needed files and store the full paths in a text file

then used a shell script to get them one by one

I have also used sytem/exec/passthru to get or scp files as well

carlsimon510

7:59 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



Really, I am open to any ideas, don't neccessarily need to do it in php. I was just thinking this would be the best way. I need to do all the steps outlined in the first post I made, but to take it one step further, I need to automate the running of this procedure to run once daily. My thought process was to put everything in a php script, then call it from crontab file nightly at 2am.

Thanks, Carl

jatar_k

8:01 pm on Aug 14, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



we used to do the same thing using a shell script

tar up all the files
gz that
scp to other server

we then scheduled that, very easy. Though not everyone has the ability to use shell scripts.

carlsimon510

8:10 pm on Aug 14, 2006 (gmt 0)

10+ Year Member



Thanks, I will look into scp. I assume I can copy from an ftp site as well as copy to an ftp site?

Thanks, Carl

jatar_k

10:28 pm on Aug 14, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would think so

carlsimon510

7:32 pm on Aug 28, 2006 (gmt 0)

10+ Year Member



Well, I have written my script using scp, but I cannot get it to bypass asking me for the password. I have researched online, found the shared keysmethod of fixing this, but still it asks me for a password. I tried creating the key on my machine, then putting the public one on the machine I am scp to, and vice versa, same result, I am prompted for a password.

Are there any alternatives? Other than this, my script runs flawlessly, unfortunately, I need this piece for automation.

Thanks, Carl