ftp problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

ftp problems

Post by Bill H »

I am having a problem with an ftp connection on a unix server.

Code: Select all

<?php
// set up basic connection
$conn_id = ftp_connect("www.sitename.com");

if (!$conn_id)
     echo "FTP connection not made successfully.";
else
{
     // login with username and password
     $login_result = ftp_login($conn_id, "username", "password");

     // check connection
     if (!$login_result)
           echo "FTP connection has failed!";
     else 
     {    echo "Connected to proper server.";

          echo ftp_pwd($conn_id);
          echo "<br>";

          ftp_chdir($conn_id, "newdir");
          echo "<br>";

         ftp_get($conn_id, "C:/Temporary/filename.doc", "filename.doc",   FTP_BINARY);
          echo "<br>";
          ftp_get($conn_id, "C:/Temporary/filename.doc", "newdir/filename.doc", FTP_BINARY);
          echo "<br>";
     }
     // close the FTP stream
     ftp_close($conn_id);
}
?>
The above code echoes
Connected to proper server
/
Warning: ftp_chdir(): newdir: No such file or directory.
Warning: ftp_get: filename.doc: No such file or directory.
Warning: ftp_get: newdir/filename.doc: No such file or directory.
A call to ftp_nlist($conn_id, "/"); returns an empty list.

It seems it is connecting and logging in but cannot see the directories and files that are there. (They are there. I use WS_FTP and can see them.)

What am I missing?
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

What version of php, what OS. I ran into this problem with php 4.2 on windows, the function was fixed in 4.3
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

oops, my bad.
My hosting company has a few little wierd quirks and I wasn't logging in where I thought I was.
I needed to change to the "/www" directory first.

But I still have a problem with the file download.
Warning: ftp_get(): error opening C:/Temporary/filename.doc in /data/web/.../ftp_test.php on line 19 (the ftp_get() line)
What do I not know about creating a file on the local disk?
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

Found out what I didn't know.
This function cannot access the machine on which the browser is running.
:(
Post Reply