• 0

Help with FTP in PHP


Question

I tried to write a PHP script for my jobs ftp but I keep getting this error.

Connecting to 64.118.238.214 via FTP

Connected...

Warning: ftp_nlist(): php_connect_nonb() failed: No route to host (113) in /home/alien0us/public_html/static/ftp_ez.php on line 38

Warning: Invalid argument supplied for foreach() in /home/alien0us/public_html/static/ftp_ez.php on line.

here is the source below:

<?php

// ftp script for default user

// fiberlinked@linux.net for questions/comments/death threats

// begin ->

// some variables

$host = "hostsIP";

$un = "def_username";

$pw = "def_password";

echo "Connecting to " . $host . " via FTP";

// connection code block

$ftp_conn = ftp_connect($host) or die("Could not connect to FTP server");

$ftp_login = ftp_login($ftp_conn, $un, $pw) or die("Unable to login");

// end connection code block

// enable passive mode

$mode = ftp_pasv($ftp_conn, TRUE);

// end enable passive mode

// check login & connection

if((!$ftp_conn) || (!$ftp_login) || (!$mode)) {

echo "FTP connection failed.";

}

else {

echo "Connected...";

}

// end login & connection check

// run nlist to list directory contents

$dir_list = ftp_nlist($ftp_conn, "");

foreach ($dir_list as $list) {

echo "$list";

}

//close

ftp_close($ftp_conn);

// end <-

?>

any help?

Edited by fiberLinked
Link to comment
https://www.neowin.net/forum/topic/215975-help-with-ftp-in-php/
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Check the comments at the bottom of http://php.net/ftp_nlist

There are several people who reported problems with the function. Maybe you should try ftp_rawlist() instead. Someone posted code that converts the output of rawlist to nlist, so it shouldn't be too hard to implement into your existing script.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.