The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> System Administration
> FTP Help
|
NEWBIE:: Using fopen where FTP functions not available
Discuss NEWBIE:: Using fopen where FTP functions not available in the FTP Help forum on Dev Shed. NEWBIE:: Using fopen where FTP functions not available FTP Help forum discussing FTP practices, tips and solutions for problems with FTP on multiple platforms. File Transfer Protocol (FTP) was designed specifically for transferring files from one machine to another.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 18th, 2001, 09:52 PM
|
 |
No one Important
|
|
Join Date: Aug 2000
Location: Australia
Posts: 524
Time spent in forums: 12 h 38 m 24 sec
Reputation Power: 13
|
|
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
|

July 18th, 2001, 10:48 PM
|
|
Contributing User
|
|
Join Date: Jun 2001
Location: Australia
Posts: 10
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
|

July 18th, 2001, 10:53 PM
|
|
Embittered Cynic
|
|
Join Date: Jul 2001
Location: 38.97° N, 94.67° W
Posts: 11
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
|

July 18th, 2001, 10:58 PM
|
|
Contributing User
|
|
Join Date: Jun 2001
Location: Australia
Posts: 10
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.. 
|

July 18th, 2001, 11:18 PM
|
 |
Big Endian
|
|
Join Date: May 2001
Location: Fly-over country
|
|
|
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...
|

July 18th, 2001, 11:20 PM
|
|
Contributing User
|
|
Join Date: Jun 2001
Location: Australia
Posts: 10
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 
|

July 18th, 2001, 11:44 PM
|
|
Embittered Cynic
|
|
Join Date: Jul 2001
Location: 38.97° N, 94.67° W
Posts: 11
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.
|

July 19th, 2001, 11:00 PM
|
 |
No one Important
|
|
Join Date: Aug 2000
Location: Australia
Posts: 524
Time spent in forums: 12 h 38 m 24 sec
Reputation Power: 13
|
|
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? 
|

July 19th, 2001, 11:14 PM
|
|
Embittered Cynic
|
|
Join Date: Jul 2001
Location: 38.97° N, 94.67° W
Posts: 11
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.
|

July 19th, 2001, 11:33 PM
|
|
Embittered Cynic
|
|
Join Date: Jul 2001
Location: 38.97° N, 94.67° W
Posts: 11
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.
|

July 20th, 2001, 10:02 PM
|
|
Embittered Cynic
|
|
Join Date: Jul 2001
Location: 38.97° N, 94.67° W
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
bump
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|