Jump to content

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/
Share on other sites

[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>

 

  1. If you're in telnet, type ftp ftp2.bom.gov.au ( or see Starting FTP )
  2. When prompted for user-id, enter anonymous.
  3. When prompted for the password, enter your e-mail address ( or guest )
  4. Type ls
  5. Use an ftp command to download the required information.
  6. Type quit to finish FTP session.

 

UserName: anonymous

 Password:  your e-mail address

 

Works for me as you can see from the log.

 

Edited by jazzman1
Link to comment
https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476485
Share on other sites

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");
   }
}
Link to comment
https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476492
Share on other sites

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");
   }
}
Link to comment
https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476493
Share on other sites

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 by serpent
Link to comment
https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476496
Share on other sites

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");
    }
}


"

Link to comment
https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476534
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476584
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/287842-ftp-cant-connect/#findComment-1476587
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.