![]() Topic awaiting preservation: read remote file via FTP (PHP) (Page 1 of 1) |
|
|---|---|
|
Maniac (V) Inmate From: there...no..there..... |
posted 06-13-2005 14:57
I am trying to open a file for read-only on a remote server. I have set the chmod of the file to 666 (and 777 just to test) and it still says that the file can not be opened for read-only. code: $ftp_server = "69.93.246.225";
$ftp_user = "user";
$ftp_pass = "password";
$fpt_file = "test.txt";
// 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 <br />\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}
//check passive mode
if(ftp_pasv($conn_id, true)){
echo "Passive mode on<br />\n";
}else{
echo "Passive mode off<br />\n";
}
// what directory are we in?
print ("Working directory : " . ftp_pwd($conn_id) . "<br />\n");
//change directories
if(@ftp_chdir($conn_id, "database")){
echo "Changed directories <br />\n";
}else{
echo "Can't change directories <br />\n";
}
// what directory are we in now?
print ("Working directory : " . ftp_pwd($conn_id) . "<br />\n");
//see if the playerstatus.fpt exists
if(!$fpt_file){
echo "$fpt_file Doesn't seem to be here <br />\n";
}else{
echo "$fpt_file is here <br />\n";
}
if(!(fopen($fpt_file,"r"))){
print("Can't open the file");
}else{
print("File is open");
}
// close the connection
ftp_close($conn_id);
|
|
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
posted 06-13-2005 17:33
Alright you have an issue here code: //see if the playerstatus.fpt exists
if(!$fpt_file){
echo "$fpt_file Doesn't seem to be here <br />\n";
}else{
echo "$fpt_file is here <br />\n";
}
|
|
Maniac (V) Inmate From: there...no..there..... |
posted 06-13-2005 18:42
OK.......changed that and it says that the file has been downloaded, but where does it download it to? It's not on the server that is running this script........sorry.........I'm confused code: //try to download the file
if (ftp_get($conn_id,$fpt_file)) {
echo "$fpt_file Failed to download <br />\n";
}else{
echo "$fpt_file has been downloaded <br />\n";
}
|
|
Maniac (V) Inmate From: there...no..there..... |
posted 06-13-2005 18:48
ok........I changed it to this: code: $localfile = "testText.txt";
//try to download the file
if (ftp_get($conn_id,$fpt_file,$localfile, FTP_BINARY)) {
echo "$fpt_file Failed to download <br />\n";
}else{
echo "$fpt_file has been downloaded <br />\n";
}
|
|
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
posted 06-13-2005 18:53
Well there's not an ftp method for reading a file so your best bet is downloading it and then using the regular file reading methods for reading the file. code: // Straight from the fopen page
$handle = fopen("ftp://$ftp_user:$ftp_pass@$ftp_server/database/$fpt_file", "r");
$text = fread($handle, 4976);
echo $text;
|
|
Maniac (V) Inmate From: there...no..there..... |
posted 06-13-2005 20:42
quote:
quote:
quote:
quote:
|
|
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
posted 06-13-2005 21:10
quote:
|
|
Maniac (V) Inmate From: there...no..there..... |
posted 06-13-2005 23:06
well, i am not sure that that is going to do the trick. I'm trying to modify a script and it's starting to be kind of a pain in the ass (for me at least). |