Jump to content

Archived

This topic is now archived and is closed to further replies.

l3lade

getfile ?

Recommended Posts

how do i get a file from a remote server then save it localy. then i will cronjob it

Share this post


Link to post
Share on other sites
please can someone tell me the code to get a remote file because i cant find it anywere then the code to save it somewere local

Share this post


Link to post
Share on other sites
You can't write a script that sits on the server and forces a download to the client!!!! It would be a very dangerous world if that were common place.

The best you could do is e-mail the file as an attachment. At least you can do that in a cron job and still not have to worry about the destination machine being on or not.

Share this post


Link to post
Share on other sites
sorry you obiouasy dont understand what i want is.

1. get a file from a REMOTE server

2. save it to my local WEBSERVER

hope that helps you to help me :P

Share this post


Link to post
Share on other sites
Do you have permission to get the file? Do you always know the file's name? Or at least part of the name? If so, look at the [a href=\"http://www.php.net/ftp\" target=\"_blank\"]ftp functions[/a].

Ken

Share this post


Link to post
Share on other sites
ok now im getting problems with that. i get this error

[code]Parse error: parse error, unexpected T_DNUMBER, expecting T_VARIABLE or '$' in /home/rmmsclan/public_html/main/mani_stats/ranks/index.php on line 8[/code]

useing this code (but with pass login and server ip)

[code]<?php

// define some variables
$local_file = 'local.zip';
$server_file = 'server.zip';

// set up basic connection
$conn_id = ftp_connect($***.***.**.***);

// login with username and password
$login_result = ftp_login($conn_id, $******, $******);

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
   echo "Successfully written to $local_file\n";
} else {
   echo "There was a problem\n";
}

// close the connection
ftp_close($conn_id);

?>[/code]

Share this post


Link to post
Share on other sites
Why are you putting a $ in front of the ip on the following line?

[code]$conn_id = ftp_connect($***.***.**.***);[/code]

Share this post


Link to post
Share on other sites
i took it away and still have the error. i found out that if i take away the decimals i get this error

[code]Warning: ftp_connect(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /home/rmmsclan/public_html/main/mani_stats/ranks/index.php on line 8

Warning: ftp_login() expects parameter 1 to be resource, boolean given in /home/rmmsclan/public_html/main/mani_stats/ranks/index.php on line 11

Warning: ftp_get() expects parameter 1 to be resource, boolean given in /home/rmmsclan/public_html/main/mani_stats/ranks/index.php on line 14
There was a problem
Warning: ftp_close() expects parameter 1 to be resource, boolean given in /home/rmmsclan/public_html/main/mani_stats/ranks/index.php on line 21[/code]

ps. this is a game server and the ip: 195.149.21.123 and this works in smart ftp and in the windows network thing but im not sure if its right for this :S

Share this post


Link to post
Share on other sites
[code]$conn_id = ftp_connect("***.***.**.***");[/code]

the IP is a string, so treat it as such and put quotes around it.

Share this post


Link to post
Share on other sites
ok i can feel that were clos now, but im getting this error

[code]Warning: ftp_login(): Please tell me who you are in /home/rmmsclan/public_html/main/mani_stats/ranks/index.php on line 11

Warning: ftp_get(): Error opening mani_ranks.txt in /home/rmmsclan/public_html/main/mani_stats/ranks/index.php on line 14
There was a problem[/code]

could this be to do with the conn_id thing?

Share this post


Link to post
Share on other sites
ok so now it takes ages to load whitch at first i was happy about but once it had done i get this error

[code]
Warning: ftp_login() expects parameter 1 to be resource, boolean given in /home/rmmsclan/public_html/main/mani_stats/ranks/index.php on line 11

Warning: ftp_get() expects parameter 1 to be resource, boolean given in /home/rmmsclan/public_html/main/mani_stats/ranks/index.php on line 14
There was a problem
Warning: ftp_close() expects parameter 1 to be resource, boolean given in /home/rmmsclan/public_html/main/mani_stats/ranks/index.php on line 21[/code]

... what im i doing now?

also it overwrites the old file with an empty one

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.