cancel
Showing results for 
Search instead for 
Did you mean: 

FTP_GET

N/A

FTP_GET

I copy a file from one directory on my http server to another, so I have a PHP script GET it from the http server to the cgi server, and then copy it to its destination. The FTP_GET() fails on the ccgi server, but worked on the old one.
The code is:

$tempname = './tempfile/'.mktime().'.tmp';
if(!ftp_get($conn_id, $tempname, "/htdocs/filestore/$FileName", FTP_BINARY)){cdiFatalMessage("Download failed path:".$tempname);}

and the directory tempfile exists with CHMOD 777 but I get the message

Warning: ftp_get(): Unable to build data connection: Connection refused in ./cgi-php/createDailyInstance.php on line 106

which I think just means that it failed.

Any suggestions as to what I should be looking at to get this working would be appreciated.
16 REPLIES
Ben_Brown
Grafter
Posts: 2,839
Registered: 13-06-2007

FTP_GET

Unfortunately I don't think that you can make direct connections to the FTP server in this way for security reasons.

You could use the wget command as an alternative, e.g.:

wget -q ftp://jalamb:*password*@ftp.force9.net/htdocs/filestore/$FileName


If you're doing this non-interactively e.g. in cron you could use a simpler bash script to do this (save it as getfile.sh and chmod to 750, after adjusting the username and password):


#!/bin/bash
if [ ! -n "$1" ]; then
echo "usage: $(basename $0) file"
exit
fi
wget -q ftp://username:password@ftp.force9.net$1
if [ $? -ne 0 ]; then
echo "Error downloading file $1"
fi


You'd then specify the file as an argument to the script, e.g.

getfile.sh /htdocs/filestore/$FileName


Hope that helps.
N/A

FTP_GET

WGET seems find for getting a file from homepages to ccgi but what about going the otherway? I have a cron job which creates a new htm file everyday which I htne copy (via FTP) to homepages but this fails on the new server.
N/A

FTP_GET

Thanks for this reply.

The actualy situation is that this is a PHP script being run by an incoming Paypal Instant Payment Notification message. In response to the message arriving, files are copied from one directory on the HTTP server, to another on that same server, (for download by the user).
The PHP does sucessfully create a new directory on the HTTP server via FTP, but fails on the GET.

It works happily on the old cgi server, so it will be the new security settings

I will investigate the WGET command, and see if I can get it to work.

If it does, then I will have advanced to the position of "qtech", with the problem of copy the file back to the new directory.
N/A

FTP_GET

I have looked into the wget suggestion, but I don't think it helps.

I tried various things and eventually (from PHP):

$output = shell_exec('wget -q ftp://username:password@homepages.force9.net/htdocs/filestore/filename.xxx');


which gave me the response:

sh: line 1: /usr/bin/wget: Permission denied

I must emphasize that I don't think that *getting* the FTP connection is the problem. My PHP code sucessfully creates the FTP connection and sucessfully uses it to create a directory on the homepages server.

Also, this code works sucessfully on the old cgi server, so the problem cannot be getting into the homepages server, but must be the file coming in to the ccgi server.

As I said before, what I am actually trying to do is to copy a file, already on the homepages server, to another location on that same server (but copy, not rename). The only way I could think to do that was to use FTP GET and PUT, going via the cgi server on which the PHP program is running.

Any ideas would be welcomed.
Ben_Brown
Grafter
Posts: 2,839
Registered: 13-06-2007

FTP_GET

I've been digging a bit deeper, and it seems that while wget works from the command line it doesn't when called via a browser, either using php or a shell script.

Unfortunately the people I need to talk to about this are not available at the weekend, I'll try and get more information for you tomorrow.
N/A

FTP_GET

I still can't see any way of getting this to work on the new machine, so I am going to have to redesign and redevelop my application. The end result will be less secure than previously, but I need something in place.
N/A

FTP_GET

I agree it lookslike we've been stuffed. One option would be to transfer the whole of my site (inc static pages) to the new CGI server but I am not sure this would be desirable or robust.

Otherwsie a complete re-think lwould seem to be in order. It is a shame I've always found F9 really good but I may have to look elsewhere to get the service I need. Pity!
Community Veteran
Posts: 1,136
Thanks: 2
Registered: 30-07-2007

FTP_GET

Its for this very reason I decided to host my web, cgi and sql on a small (AMD XP 2200+, 512Mb, 40Gig local, 40 network) FreeBSD machine at home. Granted my sites arn't getting many hits and the sql load is minimal, but for a home user running a hobby site with mediawiki and phpBB its enough to work with and the users don't complain about slowness or downtime (except when I reboot the box)
F9 member since 4 Sep 1999
F9 ADSL customer since 27 Aug 2004
DLM manages your line the same way DRM manages your rights.
Look at all the pretty graphs! (now with uptime logging!)
Ben_Brown
Grafter
Posts: 2,839
Registered: 13-06-2007

FTP_GET

I host a couple of small sites and my email on an old Celeron 466 with 96MB RAM with NetBSD (ok, we're getting off topic here!).

It's not good for heavy use but a very good learning experience and has taught me a lot over the last 3 years or so that I've been running it.
N/A

Progress?

Any one had any luck finding a solution/work around to this one yet?

TIA

Shaun
N/A

FTP_GET

No. I never found a solution.
The problem is only on copying from the homepage server to the ccgi, so I have changed my application and now store my data files on the ccgi server,
N/A

Moving files between cgi server and web server

ftp_put doesn't seem to work either, since the move to the new cgi platform. It creates the file on the web server, but does not transfer the file contents.

I am stumped, since the script worked fine on the old platform, and also works on my home computer.

Kev.
N/A

FTP_GET

You're right! I didn't check that the files actually had content. It all appears to work, with success messages, but results in empty files.

This really means that cgi can have very little influence on the contents of the homepage machine and makes a secure download mechanism very difficult. I will have to try looking at storing my files in the SQL database, or maybe zipping them with passwords and storing the passwords in the database. - More redesign and programming work.

BenBrown was supposed to be talking to people who were "not available at the weekend" - did he find any answers please ?
JonathanW
Grafter
Posts: 2,648
Registered: 02-10-2007

FTP_GET

Hi,

Ben did have a word with the people in question, and it appears that his comments about it not working from a browser are correct. Though it should still be possible to run it via cron or the command line.

I know its possible to do the above from a perl script, as I've got one running on my own ccgi space to back everything up to the homepages server, though this is running from cron, and has also been tested from the comand line.