I'm trying to make a ftp script that uploads a file from my web server over to my TF2 game server and its having trouble doing so.
Information about the script
The web server is running on linux
The Game server is running on windows
The script does find the local file
It is connecting to the remote ftp
It is finding the correct directory where the text file should be uploading
It doesn't have to chmod because its uploading to a windows server (Maybe)
The file is writing to the local txt file correctly
The error - Its finding the local one for some reason it can't locate the remote one, if I search the directory it does find the file im trying to replace though.:
Warning: ftp_put() [function.ftp-put]: The system cannot find the file specified. in /chroot/home/august5t/august5th.org/html/admin/pages/assets/viewweapons.php on line 229
<?php
include('db.php');
include('switch.php');
error_reporting(E_ALL);
ini_set('display_errors', 1);
$query = "SELECT * FROM weapons ORDER BY steamid";
if ($stmt = $mysqli->prepare($query) or die($mysqli)) {
$stmt->execute();
$stmt->bind_result($id, $steamid, $wepid, $weplvl, $weprare, $attr1, $attr2, $attr3, $attr4, $attr5, $attr6, $attr7, $attr8, $attr9, $attr10, $attr11, $attr12, $attr13, $attr14, $attr15, $attr16, $val1, $val2, $val3, $val4, $val5, $val6, $val7, $val8, $val9, $val10, $val11, $val12, $val13, $val14, $val15, $val16);
while ($row = $stmt->fetch()) {
$wep = $wepid;
$wep = wepname($wep);
$steamids[] = array('steamid' => $steamid);
$data[] = array(
'steam' => $steamid,
'wepid' => $wepid,
'weplvl' => $weplvl,
'wepname' => $wep,
'weprare' => $weprare,
'attr1' => $attr1,
'attr2' => $attr2,
'attr3' => $attr3,
'attr4' => $attr4,
'attr5' => $attr5,
'attr6' => $attr6,
'attr7' => $attr7,
'attr8' => $attr8,
'attr9' => $attr9,
'attr10' => $attr10,
'attr11' => $attr11,
'attr12' => $attr12,
'attr13' => $attr13,
'attr14' => $attr14,
'attr15' => $attr15,
'attr16' => $attr16,
'val1' => $val1,
'val2' => $val2,
'val3' => $val3,
'val4' => $val4,
'val5' => $val5,
'val6' => $val6,
'val7' => $val7,
'val8' => $val8,
'val9' => $val9,
'val10' => $val10,
'val11' => $val11,
'val12' => $val12,
'val13' => $val13,
'val14' => $val14,
'val15' => $val15,
'val16' => $val16,
);
}
$stmt->close();
}
$arr= array_map('unserialize', array_unique(array_map('serialize', $steamids)));
$myFile = "weapons/tf2items.weapons.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
chmod("weapons/tf2items.weapons.txt", 0777);
fwrite($fh, '"' . 'custom_weapons_v3' . '"' . "\r\n");
fwrite($fh, ' {' . "\r\n");
foreach($arr as $key => $a){
fwrite($fh, "\r\n");
$check = $a['steamid'];
fwrite($fh, " $check");
fwrite($fh, "\r\n");
fwrite($fh, "{");
fwrite($fh, "\r\n");
foreach($data as $key => $r){
$check2 = $r['steam'];
if($check == $check2){
fwrite($fh, ' "' . $r['wepid'] .'"' . " " . '//' . $r['wepname'] . "\r\n" );
fwrite($fh, " {" . "\r\n");
fwrite($fh, ' "level"' . ' "' . $r['weplvl'] . '"' . "\r\n");
fwrite($fh, ' "quality"' . ' ' . '"' . $r['weprare'] . '"' . "\r\n");
if($r['attr1'] === 0 || $r['attr1'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "1"' . ' "' . $r['attr1'] . ' ; ' . $r['val1'] . '"' . "\r\n");
}
if($r['attr2'] === 0 || $r['attr2'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "2"' . ' "' . $r['attr2'] . ' ; ' . $r['val2'] . '"' . "\r\n");
}
if($r['attr3'] === 0 || $r['attr3'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "3"' . ' "' . $r['attr3'] . ' ; ' . $r['val4'] . '"' . "\r\n");
}
if($r['attr4'] === 0 || $r['attr4'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "4"' . ' "' . $r['attr4'] . ' ; ' . $r['val4'] . '"' . "\r\n");
}
if($r['attr5'] === 0 || $r['attr5'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "5"' . ' "' . $r['attr5'] . ' ; ' . $r['val5'] . '"' . "\r\n");
}
if($r['attr6'] === 0 || $r['attr6'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "6"' . ' "' . $r['attr6'] . ' ; ' . $r['val6'] . '"' . "\r\n");
}
if($r['attr7'] === 0 || $r['attr7'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "7"' . ' "' . $r['attr7'] . ' ; ' . $r['val7'] . '"' . "\r\n");
}
if($r['attr8'] === 0 || $r['attr8'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "8"' . ' "' . $r['attr8'] . ' ; ' . $r['val8'] . '"' . "\r\n");
}
if($r['attr9'] === 0 || $r['attr9'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "9"' . ' "' . $r['attr9'] . ' ; ' . $r['val9'] . '"' . "\r\n");
}
if($r['attr10'] === 0 || $r['attr10'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "10"' . ' "' . $r['attr10'] . ' ; ' . $r['val10'] . '"' . "\r\n");
}
if($r['attr11'] === 0 || $r['attr11'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "11"' . ' "' . $r['attr10'] . ' ; ' . $r['val10'] . '"' . "\r\n");
}
if($r['attr12'] === 0 || $r['attr12'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "12"' . ' "' . $r['attr12'] . ' ; ' . $r['val12'] . '"' . "\r\n");
}
if($r['attr13'] === 0 || $r['attr13'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "13"' . ' "' . $r['attr13'] . ' ; ' . $r['val13'] . '"' . "\r\n");
}
if($r['attr14'] === 0 || $r['attr14'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "14"' . ' "' . $r['attr14'] . ' ; ' . $r['val14'] . '"' . "\r\n");
}
if($r['attr15'] === 0 || $r['attr15'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "15"' . ' "' . $r['attr15'] . ' ; ' . $r['val15'] . '"' . "\r\n");
}
if($r['attr16'] === 0 || $r['attr16'] === ''){
fwrite($fh, '');
}else{
fwrite($fh, ' "16"' . ' "' . $r['attr16'] . ' ; ' . $r['val16'] . '"' . "\r\n");
}
fwrite($fh, " }" . "\r\n");
fwrite($fh, "\r\n");
}
}
fwrite($fh, " }" . "\r\n");
fwrite($fh, "\r\n");
}
fwrite($fh, " }");
fclose($fh);
$ftp_server="174.34.132.106";
$ftp_user_name="username";
$ftp_user_pass="password";
$remote_file = "tf2items.weapons.txt";
$file = "weapons/tf2items.weapons.txt";//tobe uploaded
if(!file_exists($file)) echo "The local file does not exist";
$conn_id = ftp_connect($ftp_server) or die('Unable to create the connection');
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_chdir($conn_id, "174.34.132.106 port 27015/tf/addons/sourcemod/configs/");
echo ftp_pwd($conn_id);
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
exit;
} else {
echo "There was a problem while uploading $file\n";
exit;
}
// close the connection
ftp_close($conn_id);
?>