Page 1 of 1

How to implement a FTP page?

Posted: Thu Sep 29, 2005 12:45 pm
by ljCharlie
Is it possible to create a interface to log into an FTP site? I'm trying to ceate an interface so user can login with their user name and password and the have the option to log into our FTP server. Is this possible? What are the requirements and codes?

Thanks!

Posted: Thu Sep 29, 2005 12:52 pm
by shiznatix
check out the manual for the ftp commands. start with ftp_connect(); this is possible.

Posted: Thu Sep 29, 2005 1:06 pm
by ljCharlie
Many thanks for the help. I saw this site, http://web2ftp.com/ and I think something like this would work.

By the way, is ftp_connect() a command of PHP or FTP?

Again, thanks!

Posted: Thu Sep 29, 2005 1:08 pm
by John Cartwright
It's php.. but it connects to ftp servers via ftp protocols :arrow: http://ca.php.net/ftp_connect

Posted: Fri Sep 30, 2005 9:00 am
by ljCharlie
Many thanks for the help. I used this codes:

Code: Select all

// set up basic connection
	$conn_id = ftp_connect("myWebsite.com");
	$ftp_user_name = $_SESSION['kt_login_user'];
	$ftp_user_pass = $_SESSION['kt_pssWord'];
	$ftp_server = "My Sever";
	$ftp_user_name = $ftp_user_name;
	//echo "user Name: ".$ftp_user_name."<br> Password: ".$ftp_user_pass."<br>";

// 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";
       exit;
   } else {
       echo "Connected to $ftp_server, for user $ftp_user_name";
   }
And I got connected; however, I do not see my files and folders listed. I'm definitely missing something. In addition, once I got connected and it shows my folder and files, can I just drag and drop files into it or from it?

Thank you.

Posted: Fri Sep 30, 2005 9:04 am
by shiznatix
that will just connect you to the ftp, not give you a full ftp GUI menu and everything. if you want that you will have to build it yourself. try using readdir and simmiliar functions to read teh contents of the folders. then make it links and stuff.

Posted: Fri Sep 30, 2005 9:11 am
by ljCharlie
Many thanks for your help. I'm totally new to this FTP thing inside a browser using PHP. Your help are very much appreciated.

Here is what I found out so far about the problem. According to the FTP server log, when I got connected somehow I automatically got disconnected or closed again. What would have caused that?

Posted: Fri Sep 30, 2005 9:25 am
by shiznatix
the connection only lasts for the durration of the script loading. each time the user clicks a link in the ftp thing you are going to have to run the connect thing again.

Posted: Fri Sep 30, 2005 9:25 am
by ljCharlie
Okay, I guess I've been thinking too hard here. Simple question. I found that I can do this, ftp.mysite.com, on the MS IE browser as the address and it would automatically log me into the Anonymous account folder. Now, how do I do change this, ftp.mysite.com, so that when I log in it will automatically go to a particular user's folder?

Thanks!

Posted: Fri Sep 30, 2005 10:10 am
by pilau
You need to login as the user, with the username and password.

Posted: Fri Sep 30, 2005 10:20 am
by ljCharlie
Yes, I understand that I need to login as the user and with his password but what's the actual method. For example:

Do I type in like this, ftp.mysite.com:myusername:myPassword/myfolder or something different?

Posted: Fri Sep 30, 2005 10:51 am
by pilau
ljCharlie wrote:Yes, I understand that I need to login as the user and with his password but what's the actual method. For example:

Do I type in like this, ftp.mysite.com:myusername:myPassword/myfolder or something different?
No. it's username:password@ftp.domain.com

Posted: Fri Sep 30, 2005 11:36 am
by ljCharlie
Okay, thanks that works! Now, here's the question. What are the advantages and disadvantages of creating my own PHP FTP client interface and just do something like this:

Code: Select all

<a href="ftp://<?php echo $ftp_user_name; ?>:<?php echo $ftp_user_pass; ?>@myDomain.com">FTP Click here</a>
The one problem I found so far with this simple method is that when you mouse over the link, the user name and password is showing in the browser's status bar at the bottom. In addition, if you go to view source the user name and password is also there and I'm guessing it is in the browser's cache directory as well. That means anyone can login to the FTP server if the user does not lock his/her computer.

Any suggestion on the best option with the least amount of work to implement?