serpent Posted April 17, 2014 Share Posted April 17, 2014 Hey all, Im trying to create a php script to replicate the following weather radar http://www.bom.gov.au/products/IDR703.loop.shtml they have supplied people with a ftp (it has no user/pass) ftp://ftp2.bom.gov.au/anon/gen/radar/ so this is my code and it wont even connect. <?php $ftp_server = "ftp2.bom.gov.au"; // set up a connection or die $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); ?> I think it might be the ftp itself? Quote Link to comment https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/ Share on other sites More sharing options...
jazzman1 Posted April 17, 2014 Share Posted April 17, 2014 (edited) [jazz@centos-box ~]$ ftp ftp2.bom.gov.au Connected to ftp2.bom.gov.au (134.178.63.130). 220-Welcome to the Bureau of Meteorology FTP service. 220- 220- Disclaimer 220- 220-You accept all risks and responsibility for losses, damages, costs and 220-other consequences resulting directly or indirectly from using this site and 220-any information or material available from it. 220- 220-To the maximum permitted by law, the Bureau of Meteorology excludes all 220-liability to any person arising directly or indirectly from using this 220-site and any information or material available from it. 220- 220-Always Check the Information 220- 220-Information at this site: 220- 220-. is general information provided as part of the Bureau of Meteorology's 220- statutory role in the dissemination of information relating to 220- meteorology. 220-. is subject to the uncertainties of scientific and technical research 220-. may not be accurate, current or complete 220-. is subject to change without notice 220-. is not a substitute for independent professional advice and users 220- should obtain any appropriate professional advice relevant to their 220- particular circumstances 220-. the material on this web site may include the views or recommendations 220- of third parties, which do not necessarily reflect the views of the 220- Bureau of Meteorology or indicate its commitment to a particular course of 220- action. 220 Name (ftp2.bom.gov.au:jazz): anonymous 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> If you're in telnet, type ftp ftp2.bom.gov.au ( or see Starting FTP ) When prompted for user-id, enter anonymous. When prompted for the password, enter your e-mail address ( or guest ) Type ls Use an ftp command to download the required information. Type quit to finish FTP session. UserName: anonymous Password: your e-mail address Works for me as you can see from the log. Edited April 17, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476485 Share on other sites More sharing options...
boompa Posted April 17, 2014 Share Posted April 17, 2014 Quick example: <?php $conn = ftp_connect("ftp2.bom.gov.au"); if (!$conn) { echo "Couldn't connect to server\n"; return 1; } if (ftp_login($conn, "anonymous", "test@example.com")) { $files = ftp_nlist($conn, "anon/gen/radar"); foreach($files as $file) { print("File: $file\n"); } } Quote Link to comment https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476492 Share on other sites More sharing options...
jazzman1 Posted April 17, 2014 Share Posted April 17, 2014 Don't forget to turn passive mode on if the server required. $conn = ftp_connect("ftp2.bom.gov.au"); if (!$conn) { echo "Couldn't connect to server\n"; return 1; } if (ftp_login($conn, "anonymous", "test@example.com")) { // turn passive mode on ftp_pasv($conn, true); $files = ftp_nlist($conn, "anon/gen/radar"); foreach($files as $file) { print("File: $file\n"); } } Quote Link to comment https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476493 Share on other sites More sharing options...
serpent Posted April 17, 2014 Author Share Posted April 17, 2014 (edited) I tried both of the examples above and they did not work. I think I know the issue though, I am currently at work for the next 8 days (we live on site for that duration)and our wifi has some pretty extensive port blocking, its entirely possible that port 21 is blocked (if the php protocol utilizes that port?) thanks for the quick responses by the way Edited April 17, 2014 by serpent Quote Link to comment https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476496 Share on other sites More sharing options...
jazzman1 Posted April 17, 2014 Share Posted April 17, 2014 This isn't filtered ports issue, if so you could get at least the echo of "Couldn't connect to server". If you are running into a blank page, my best guess is that there is no compiled (or it's not installed) ftp enabled support to this version of php and the directive controls whether or not and where PHP outputs errors is set to "display_errors = Off" in the php conf. file. Try the following, <?php error_reporting(E_ALL); ini_set("display_errors", 1); if (function_exists(ftp_connect)) { echo 'the function is available'; } else { echo 'the function is not available'; } $conn = ftp_connect("ftp2.bom.gov.au"); if (!$conn) { echo "Couldn't connect to server\n"; return 1; } if (ftp_login($conn, "anonymous", "test@example.com")) { // turn passive mode on ftp_pasv($conn, true); $files = ftp_nlist($conn, "anon/gen/radar"); foreach ($files as $file) { print("File: $file\n"); } } " Quote Link to comment https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476534 Share on other sites More sharing options...
serpent Posted April 18, 2014 Author Share Posted April 18, 2014 I tried the above code, this was the result Notice: Use of undefined constant ftp_connect - assumed 'ftp_connect' in C:\php\www\index.php on line 6 the function is availableCouldn't connect to server It may help to point out my setup Windows 7 Ultimate x64 php-5.5.11-Win32-VC11-x86 and i am using the built in web server This is my first attempt at anything ftp related with php, i thought id have to enable an extension dll in the php.ini but none for ftp exist Quote Link to comment https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476584 Share on other sites More sharing options...
jazzman1 Posted April 18, 2014 Share Posted April 18, 2014 No, everything is just fine. The function name should be quoted as a string parameter - if (function_exists('ftp_connect')), it was my fault. However, I see you get a message of the echo command "Couldn't connect to server", so I thing you might have a filtered ports issue. Try to install some port's scanning tool and check which ports are filtered by your ISP. I cannot recommend you a tool for windows. I'm using nmap on my linux machines, check on the web for a windows packet. Quote Link to comment https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476587 Share on other sites More sharing options...
serpent Posted April 20, 2014 Author Share Posted April 20, 2014 I will re-run the script when i get home from work in 2 days time, I am fairly certain now my work camps wifi has ports blocked. Quote Link to comment https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476721 Share on other sites More sharing options...
serpent Posted April 23, 2014 Author Share Posted April 23, 2014 Thats all it was, the ports at work were blocked. Now i can start formatting it and sorting it, thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1477061 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.