How to implement a FTP page?

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
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

How to implement a FTP page?

Post 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!
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

check out the manual for the ftp commands. start with ftp_connect(); this is possible.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

It's php.. but it connects to ftp servers via ftp protocols :arrow: http://ca.php.net/ftp_connect
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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!
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

You need to login as the user, with the username and password.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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?
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post 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
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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?
Post Reply