Dweezel Posted February 2, 2011 Share Posted February 2, 2011 I've got a script that's been running away happily as a cron job for the last few days, but it's suddenly decided to stop working. When I run the script manually it works perfectly, but not when I run it as a cron job. I've done some debugging and I've found that the cause of the problem appears to be an ftp_get function that I'm using. I'm guessing I need to either change a file path, or a file permission, but I'm not sure to what. Here's the info: $local_dir = '../../col_protected/'; $c = ftp_connect('www.mydomain.net') or die("Can't connect"); ftp_login($c,'ftp_username','ftp_password') or die("Can't login"); ftp_get($c, $local_dir.$filename, FTP_ASCII) or die("Can't transfer"); The FTP connect and login are still working fine, it's the ftp_get that's causing the problem. The '../../col_protected/' directory is on the same level as the public_html (ie. outside the public_html) with file permissions set to 777. The cron is running at /home/username/public_html/col/proc1.php Can anyone advise please? Many thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/226449-script-working-manually-but-not-as-cron-job/ Share on other sites More sharing options...
trq Posted February 2, 2011 Share Posted February 2, 2011 You need to use absolute file paths in scripts executing from cron. Either the or change the working directory to the same one the script resides within. Quote Link to comment https://forums.phpfreaks.com/topic/226449-script-working-manually-but-not-as-cron-job/#findComment-1168828 Share on other sites More sharing options...
Dweezel Posted February 2, 2011 Author Share Posted February 2, 2011 Thanks thorpe Sorry if this is a silly question, but what would the absolute path be in this situation? I can't use a http:// path as it's outside the public_html directory. Many thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/226449-script-working-manually-but-not-as-cron-job/#findComment-1168843 Share on other sites More sharing options...
BlueSkyIS Posted February 2, 2011 Share Posted February 2, 2011 probably somewhere above /home/username/public_html/col/proc1.php if you can navigate to the location via command line, you can use the command pwd to 'print the working directory', or the absolute path to where you are. Quote Link to comment https://forums.phpfreaks.com/topic/226449-script-working-manually-but-not-as-cron-job/#findComment-1168857 Share on other sites More sharing options...
Dweezel Posted February 2, 2011 Author Share Posted February 2, 2011 Thanks to both of you for your help. I tried every possible combination for the absolute path but couldn't get it to work. In the end I used Thorpe's plan B and moved the col_protected directory into the same directory as the script. I was hoping to keep it oustide the public_html, but I'll have to just http block it via htaccess. Many thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/226449-script-working-manually-but-not-as-cron-job/#findComment-1168902 Share on other sites More sharing options...
trq Posted February 2, 2011 Share Posted February 2, 2011 Have you got access to a shell? If so, just go to the directory where the script resides then issue the pwd command, this will print the path. From here, it looks like its in your home directory. /home/username/col_protected You should also move your script into your home directory. Quote Link to comment https://forums.phpfreaks.com/topic/226449-script-working-manually-but-not-as-cron-job/#findComment-1169046 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.