PDA

View Full Version : retrieve remote file via ftp



lilichic
11-30-2007, 08:30 AM
Hi, has anyone tried to use ftp_connect in php scripts?

I have a script which works fine on other servers, but, doesn't seem to connect on bluehost???

below is the script:



$ftp_server = "ftpserver"; //these have been changed
$ftp_user = "myusername"; //these have been changed
$ftp_pass = "mypassword"; //these have been changed

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}

// close the connection
ftp_close($conn_id);


the actual output says:

"Couldn't connect to ftpserver (not the real name)"

Any ideas?

Best wishes

lilichic

Basil
11-30-2007, 09:35 AM
I copied this exact script and was able to use it to connect to my bluehost ftp as well as from my bluehost site.

Using this information..


$ftp_server = "example.com";
$ftp_user = "bhuser";
$ftp_pass = "password";

lilichic
01-20-2008, 07:46 AM
Thanks Basil, I was trying to connect to a remote ftp server, not my bluehost one, I'm guessing that there's a firewall block on outgoing ftp requests (except for local IP's)

Never mind, I'll figure something out (I hope)

Thanks again.

Early Out
01-20-2008, 07:51 AM
I don't believe you can ftp to a remote server from BH. But with shell access, you can use the wget command. See this thread (http://www.bluehostforum.com/showthread.php?t=10411), and search the forums for wget.

lilichic
01-20-2008, 09:25 AM
That looks a little complicated, but, I'll give it a go with what's left of this weekend, many thanks Early Out.

Early Out
01-20-2008, 10:11 AM
Only the "tar" part is complicated. If you just want to fetch a file from elsewhere, it's just:

wget http://someotherdomain.com/thefile

sXi
01-20-2008, 10:15 AM
Google cURL


ftp download:

curl -O ftp:// [USER:PASS@] [URL.] / [PATH] / [FILE.EXT]


ftp upload:

curl -T [FILE.EXT] ftp:// [USER:PASS@] [URL.] / [PATH] /