FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 18th, 2001, 09:52 PM
mystik_web's Avatar
mystik_web mystik_web is offline
No one Important
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Australia
Posts: 524 mystik_web User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 38 m 24 sec
Reputation Power: 13
Send a message via ICQ to mystik_web
Question NEWBIE:: Using fopen where FTP functions not available

Hi there.

I was wondering if anyone can help me. I need to be able to have a php script that will read the last updated time on a file located on a remote FTP server, from where the script is located.

FTP functions have not been enabled in the version of PHP I have to work with, so I was wondering whether there was any way of doing this with using the fopen commands??

If someone could help me it would be greatly appreciated.

Cheers

Reply With Quote
  #2  
Old July 18th, 2001, 10:48 PM
nih58 nih58 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Australia
Posts: 10 nih58 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Of course you _can_ do it.. but is it really worth it..

Anyway you'll obviously need to emulate an FTP user using fput() & fgets()

Off the top of my head the commands should go something like:

USER username
PASS password
PORT 127,0,0,1,xyz
LIST
__________________
-=-=-=-=-=-=-=-=-=-=-=-=-
PHP Scripts n Stuff
http://www.bcnstech.net/
-=-=-=-=-=-=-=-=-=-=-=-=-

Reply With Quote
  #3  
Old July 18th, 2001, 10:53 PM
linear linear is offline
Embittered Cynic
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 38.97° N, 94.67° W
Posts: 11 linear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Bummer. I think the answer's no. A few things occur to me though:

1) if you have curl libraries installed, use that.
2) you could possibly use fsockopen() and speak raw FTP protocol over the socket. very very ugly. (I wouldn't touch it -- I see nih58 beat me to posting this one ) It's ugly because the FTP data and control connections exist on separate ports, and I'm pretty sure you'd need to manually fsockopen() the data port after parsing the negotiation from the data port....
__________________
+++linear+++
PHP Security Questions? start here

Reply With Quote
  #4  
Old July 18th, 2001, 10:58 PM
nih58 nih58 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Australia
Posts: 10 nih58 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yeah.. I think it would be a waste of time trying to talk FTP
Not to mention you'll have even more fun if for some reason you have to use PASV mode due to connection problems..

Reply With Quote
  #5  
Old July 18th, 2001, 11:18 PM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,172 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 29
I have no idea if this will work or not. I'm just throwing it out as a hack that I used once.

I had to run an FTP command from a VB program to an IBM mainframe. The FTP command would always work from the command prompt, but would fail using FTP controls and .dll's in my program.

Eventually I had to put all of the FTP commands into a text file. This text file had the login, password, command information, etc. I tweaked the flat file until I could run the command ftp -s:filename successfully from the system prompt.

When this ran successfully, I then ran it from inside my program using a shell command (in PHP you would want to use the system command). If you were able to pipe the output from the above command into a file on your local machine, you would be able to use fopen to examine the contents of this file for the information you needed.

As in my case, it wouldn't matter if your programming language had FTP support as long as you were able to run the command manually from the command prompt. You would have to run a command something like this:

ftp -s:commandfile > outputfile

Then use fopen to examine the contents of outputfile.

If you get really desperate, you might want to give it a try...

Reply With Quote
  #6  
Old July 18th, 2001, 11:20 PM
nih58 nih58 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Australia
Posts: 10 nih58 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
you would want to use the system command).


if you use exec("$command_line",$results);

then the results of $command_line being executed would be stored in an array.. obviously $results

Reply With Quote
  #7  
Old July 18th, 2001, 11:44 PM
linear linear is offline
Embittered Cynic
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 38.97° N, 94.67° W
Posts: 11 linear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The ftp -s hack is a Windoze idiom. Most *nix ftp clients will let you cut to the chase thusly (consult your manpage):

ftp ftp://[user:password@]host[:port]/file[/]
ftp http://host[:port]/file
ftp host:[/path/]file[/]

and will even expand globs.

Reply With Quote
  #8  
Old July 19th, 2001, 11:00 PM
mystik_web's Avatar
mystik_web mystik_web is offline
No one Important
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Australia
Posts: 524 mystik_web User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 38 m 24 sec
Reputation Power: 13
Send a message via ICQ to mystik_web
Thanks for all the replies...

But what I am after this for is to have a page that shows the clients when a file was last updated on our ftp server so they know how current the download file is.

The version of PHP that I am using was not configured with ftp functions and I am unable to change this.

So I was wondering if there was a way with the fopen to get the last update time of the file from the remote ftp server......

Does anyone know how I might do this?

Reply With Quote
  #9  
Old July 19th, 2001, 11:14 PM
linear linear is offline
Embittered Cynic
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 38.97° N, 94.67° W
Posts: 11 linear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
fopen won't do that.

Hold on, you said it's *your* ftp server?? That changes things. There are a number of ways you can work around the ftp limitation if you have access to the file is sits on.

If it were me, I'd write a shell script that ran ls -l, pick a port to run it and throw an entry into inetd.conf (essentially using inetd as a daemon to listen for requests on your selected port, and running the ls shell script when it gets a request). This is reasonably secure too (since your script doesn't accept input, it's hard to exploit). Then all you need to do is use fsockopen() to talk to your little daemon and munge the results in PHP.

You could alternatively nfs mount the directories of interest (ugh--don't do this). You could run a httpd and use HEAD requests to get the file modification time, and restrict the httpd so it only talks to your PHP web server. There's a number of other variations on the theme, but if you own the server of interest, lots of possibilities exist.

Last edited by linear : July 19th, 2001 at 11:24 PM.

Reply With Quote
  #10  
Old July 19th, 2001, 11:33 PM
linear linear is offline
Embittered Cynic
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 38.97° N, 94.67° W
Posts: 11 linear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
~puts *nix weenie hat on~

Three steps and this is done.

1) write this trivial shell script
Code:
#!/bin/sh
ls -l /path/to/the/directory


and install it somewhere you'll remember (/usr/libexec/mystik.sh is good). Set it executable.

2) edit /etc/services (as root) and add the line
mystik 30003/tcp #mystik's disk daemon

3) edit /etc/inetd.conf and add the line
mystik stream tcp root /usr/libexec/mystik.sh mystik.sh
and restart inetd (kill -HUP `cat /var/run/inetd.pid`)

You can telnet to port 30003 on the ftp serve, and if you did the steps right, the output of ls -l should get barfed out at you.

Isn't *nix great??!?

Last edited by linear : July 19th, 2001 at 11:38 PM.

Reply With Quote
  #11  
Old July 20th, 2001, 10:02 PM
linear linear is offline
Embittered Cynic
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 38.97° N, 94.67° W
Posts: 11 linear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
bump

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > NEWBIE:: Using fopen where FTP functions not available

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap