Ftp connect php network getaddresses getaddrinfo failed

php_network_getaddresses: getaddrinfo failed: Name or service not known

php_network_getaddresses: getaddrinfo failed: Name or service not known

Here is a snippet of my code

$fp = fsockopen($s['url'], 80, $errno, $errstr, 5); if($fp)< fwrite($fp, $out); fclose($fp); 

unable to connect to www.mydomain.net/1/file.php:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known

I’m using this to submit GET data to the $s['url']

I can’t figure out why. Any help would be greatly appreciated.

Solution – 1

you are trying to open a socket to a file on the remote host which is not correct. you could make a socket connection (TCP/UDP) to a port number on a remote host. so your code should be like this:

if you are trying to create a file pointer resource to a remote file, you may use the fopen() function. but to do this, you need to specify the application protocol as well.

Читайте также:  Java ssl ignore certificates

PHP provides default stream wrappers for URL file opens. based on the schema of the URL the appropriate stream wrapper will be called internally. the URL you are trying to open does not have a valid schema for this solution. make sure there is a schema like “http://” or “ftp://” in it.

so the code would be like this:

$fp = fopen('http://www.mysite.com/path/file.txt'); 

Besides I don’t think the HTTP stream wrapper (that handles actions on file resources on URLs with http schema) supports writing of data. you can use fread() to read contents of a the URL through HTTP, but I’m not sure about writing.

EDIT:
from comments and other answers I figured out you would want to send a HTTP request to the specified URL.
the methods described in this answer are for when you want to receive data from the remote URL. if you want to send data, you can use http_request() to do this.

Solution – 2

You cannot open a connection directly to a path on a remote host using fsockopen . The url www.mydomain.net/1/file.php contains a path, when the only valid value for that first parameter is the host, www.mydomain.net .

If you are trying to access a remote URL, then file_get_contents() is your best bet. You can provide a full URL to that function, and it will fetch the content at that location using a normal HTTP request.

If you only want to send an HTTP request and ignore the response, you could use fsockopen() and manually send the HTTP request headers, ignoring any response. It might be easier with cURL though, or just plain old fopen(), which will open the connection but not necessarily read any response. If you wanted to do it with fsockopen() , it might look something like this:

$fp = fsockopen("www.mydomain.net", 80, $errno, $errstr, 30); fputs($fp, "GET /1/file.php HTTP/1.1n"); fputs($fp, "Host: www.mydomain.netn"); fputs($fp, "Connection: closenn"); 

That leaves any error handling up to you of course, but it would mean that you wouldn’t waste time reading the response.

Solution – 3

If you only want to submit GET data to the URL, you should use something straightforward like file_get_contents();

$myGetData = "?var1=val1&var2=val2"; file_get_contents($url.$myGetData); 

Solution – 4

I had a similar problem on my local testserver and local testdomains e.g.: www.testdomain.loc with the function GetImageSize() ;

Solved it by adding the hostname in the hosts file on the local server:

In the file /etc/hosts I added:

192.168.1.1 www.testdomain.loc 

Solution – 5

$url /cdn-cgi/l/email-protection" data-cfemail="b7c7d6c4c4f7c0c0c099d2cfd6dac7dbd299d4d8da">[email protected]/abc.php?var1=def"; $contents = file_get_contents($url); echo $contents; 

Solution – 6

Try to set ENV PATH. Add PHP path in to ENV PATH.

In order for this extension to work, there are DLL files that must be available to the Windows system PATH. For information on how to do this, see the FAQ entitled “How do I add my PHP directory to the PATH on Windows”. Although copying DLL files from the PHP folder into the Windows system directory also works (because the system directory is by default in the system’s PATH), this is not recommended. This extension requires the following files to be in the PATH: libeay32.dll

Solution – 7

I was getting the same error of fsocket() and I just updated my hosts files

  1. I logged via SSH in CentOS server. USERNAME and PASSWORD
    type
  2. cd /etc/
  3. ls //”just to watch list”
  4. vi hosts //”edit the host file”
  5. i //” to put the file into insert mode”
  6. 95.183.24.10 [mail_server_name] in my case (“mail.kingologic.com”)
  7. Press ESC Key
  8. press ZZ

hope it will solve your problem

for any further query please ping me at http://kingologic.com

Solution – 8

In my case this error caused by wrong /etc/nsswitch.conf configuration on debian.

hosts: files myhostname mdns4_minimal [NOTFOUND=return] dns 

and everything works right now.

Solution – 9

in simple word your site has been blocked to access network. may be you have automated some script and it caused your whole website to be blocked. the better way to resolve this is contact that site and tell your issue. if issue is genuine they may consider unblocking

Solution – 10

Had such a problem (with https://github.com/PHPMailer/PHPMailer), just reload PHP and everything start worked

Solution – 11

I had a similar problem when connecting to a local MySQL database, only changed the url for the ip address 127.0.0.1 and it worked. You could change the url for the ip address of the server.

Источник

ftp_connect

ftp_connect() устанавливает FTP-соединение с указанным сервером hostname .

Список параметров

Адрес FTP-сервера. Этот аргумент не должен содержать слешей в конце и префикса ftp:// в начале.

Этот аргумент указывает альтернативный порт для подключения. Если он опущен или установлен в ноль, то будет использован FTP порт по умолчанию - 21.

Этот аргумент указывает время ожидания в секундах для всех последующих сетевых операций. Если опущен, используется значение по умолчанию - 90 секунд. Время ожидания может быть изменено и получено в любой момент при помощи функций ftp_set_option() и ftp_get_option() соответственно.

Возвращаемые значения

Возвращает FTP\Connection в случае успешного выполнения или false в случае возникновения ошибки.

Список изменений

Примеры

Пример #1 Пример использования ftp_connect()

// устанавливает соединение или выходит
$ftp = ftp_connect ( $ftp_server ) or die( "Не удалось установить соединение с $ftp_server " );

Смотрите также

  • ftp_close() - Закрывает соединение с FTP-сервером
  • ftp_ssl_connect() - Устанавливает соединение с FTP-сервером через SSL

User Contributed Notes 3 notes

Ever needed to create an FTP connection resource defaulted to a particular dir from a URI? Here's a simple function that will take a URI like ftp://username:password@subdomain.example.com/path1/path2/, and return an FTP connection resource.

function getFtpConnection ( $uri )
<
// Split FTP URI into:
// $match[0] = ftp://username:password@sld.domain.tld/path1/path2/
// $match[1] = ftp://
// $match[2] = username
// $match[3] = password
// $match[4] = sld.domain.tld
// $match[5] = /path1/path2/
preg_match ( "/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i" , $uri , $match );

// Set up a connection
$conn = ftp_connect ( $match [ 1 ] . $match [ 4 ] . $match [ 5 ]);

// Login
if ( ftp_login ( $conn , $match [ 2 ], $match [ 3 ]))
<
// Change the dir
ftp_chdir ( $conn , $match [ 5 ]);

// Return the resource
return $conn ;
>

// Or retun null
return null ;
>
?>

Sean's example is wrong, because it includes the protocol match, so result would be php_network_getaddresses: getaddrinfo failed: Name or service not known

Источник

PHP & FTP: ftp_connect error - php_network_getaddresses: getaddrinfo failed: No such host is known

// define some variables
$ftp_server= "ftp://ftp2.bom.gov.au/anon/gen/fwo";
$ftp_user_name= "anonymous";
$ftp_user_pass= "webmaster@aquaticadventur es.com.au" ;
$local_file = "4day.txt";
$server_file = "IDV10450.txt";

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) echo "FTP connection has failed!
";
echo "Attempted to connect to $ftp_server for user $ftp_user_name
";
die;
> else echo "Connected to $ftp_server, for user $ftp_user_name
";
>

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) echo "Successfully written to $local_file\n";
> else echo "There was a problem\n";
>

// close the connection
ftp_close($conn_id);

Which gives the following error;
Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\Elysian Visions\AA test page\4day.php on line 12

Warning: ftp_login() expects parameter 1 to be resource, boolean given in D:\Elysian Visions\AA test page\4day.php on line 15
FTP connection has failed!
Attempted to connect to ftp://ftp.bom.gov.au for user anonymous

I'm not sure why it won't connect to the FTP server, which is a public server provided by the Bureau of Meteorology (Government), hence the user & password.

Do I have to do something in php.ini to allow FTP via PHP? Or do I need to have an IP address to connect to instead of ftp://ftp2.bom.gov.au/anon/gen/fwo? Or do I have a stupid syntax error I can't seem to spot?

Thanks a million for your help.

Источник

Contact US

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

getting a ftp connect error

getting a ftp connect error

getting a ftp connect error

I'm trying to connect to an ftp sever but getting the following error.

Quote:

Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /directory/file.php on line 12

Warning: ftp_login() expects parameter 1 to be resource, boolean given in /directory/file.php on line 13

Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /directory/file.php on line 16

From what i've googled, it could be a setting that needs to be configured in the php.ini? if this is so, and based on my error can you advise what i'm meant to change, or maybe the code can be made to work without php.ini changes? here's my code.

CODE

$ftp_server = "ftp://ftp2.xxxx.com"; $ftp_user = "xxxx"; $ftp_pass = "xxxx"; $ftp_connect = ftp_connect($ftp_server); $ftp_loggedIn = ftp_login($ftp_connect, $username, $password); // set up a connection or die $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); $loggedIn = ftp_login($ftp_connect, $ftp_user, $ftp_pass); if (true === $ftp_loggedIn) < echo 'Success!'; >else

RE: getting a ftp connect error

you are redoing the ftp_connect on line 9 (first connected line 5) but still referencing the the resource handle created on line 5.

RE: getting a ftp connect error

Quote:

ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /directory/file.php on line 12

line 12 is this line. $ftp_connect = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

there were quite a few errors in my code (sorry!). and i've cleaned it up like so, but still returns the error above.

CODE

$ftp_connect = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); $ftp_loggedIn = ftp_login($ftp_conn, $ftp_user, $ftp_pass); if (true === $ftp_loggedIn) < echo 'Success!'; >else < throw new Exception('Unable to log in'); >ftp_close($ftp_connect);

RE: getting a ftp connect error

i'm full of mistakes today. sorry here's the corrected code but still returns the same error

CODE

$ftp_connect = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); $ftp_loggedIn = ftp_login($ftp_connect, $ftp_user, $ftp_pass); if (true === $ftp_loggedIn) < echo 'Success!'; >else < throw new Exception('Unable to log in'); >ftp_close($ftp_connect);

RE: getting a ftp connect error

Quote (php manual)

The FTP server address. This parameter shouldn't have any trailing slashes and shouldn't be prefixed with ftp://.

RE: getting a ftp connect error

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Copyright © 1998-2023 engineering.com, Inc. All rights reserved.
Unauthorized reproduction or linking forbidden without expressed written permission. Registration on or use of this site constitutes acceptance of our Privacy Policy.

Источник

Оцените статью