API Dokümantasyonu

JRodix.Com Internet Hizmetleri - RESTful API

Genel Bilgiler

Base URL: http://your-domain.com/api.php

Format: JSON

Authentication: Session-based (FTP credentials)

Rate Limit: 1 MB/s download speed

Disk Quota: Otomatik kontrol, %90'da uyarı

API Endpoints

POST Bağlantı Kur

POST /api.php?action=connect
ParametreTipZorunluAçıklama
hostnamestringEvetFTP sunucu adresi
usernamestringEvetFTP kullanıcı adı
passwordstringEvetFTP şifresi

GET Dosya Listesi

GET /api.php?action=list&path=/folder
ParametreTipZorunluAçıklama
pathstringHayırListelenecek klasör yolu (varsayılan: /)

POST YENİ Dosya Yükle

POST /api.php?action=upload
ParametreTipZorunluAçıklama
filefileEvetYüklenecek dosya
remote_pathstringHayırHedef dosya yolu (varsayılan: /dosya_adi)
max_sizeintegerHayırMaksimum dosya boyutu (varsayılan: 10MB)
auto_delete_oldbooleanHayırEski dosyaları otomatik sil (varsayılan: true)

Otomatik Eski Dosya Silme: Aynı isimde 2+ dosya varsa en eski olanı siler.

GET KOTA Disk Kotası

GET /api.php?action=quota

POST Dosya İndir

POST /api.php?action=download
ParametreTipZorunluAçıklama
remote_pathstringEvetİndirilecek dosya yolu

DELETE Dosya Sil

POST /api.php?action=delete
ParametreTipZorunluAçıklama
remote_pathstringEvetSilinecek dosya yolu

Python Örnekleri

requests Kütüphanesi ile

import requests
import json

# API Base URL
BASE_URL = "http://your-domain.com/api.php"

# 1. Bağlantı kur
def connect_ftp(hostname, username, password):
    data = {
        'hostname': hostname,
        'username': username,
        'password': password
    }
    response = requests.post(f"{BASE_URL}?action=connect", data=data)
    return response.json()

# 2. Dosya listesi al
def list_files(path="/"):
    response = requests.get(f"{BASE_URL}?action=list", params={'path': path})
    return response.json()

# 3. Disk kotası kontrol et
def check_quota():
    response = requests.get(f"{BASE_URL}?action=quota")
    return response.json()

# 4. Dosya yükle (eski dosyaları otomatik sil)
def upload_file(file_path, remote_path=None, auto_delete_old=True):
    if remote_path is None:
        remote_path = f"/{file_path.split('/')[-1]}"
    
    with open(file_path, 'rb') as f:
        files = {'file': f}
        data = {
            'remote_path': remote_path,
            'auto_delete_old': auto_delete_old
        }
        response = requests.post(f"{BASE_URL}?action=upload", files=files, data=data)
    return response.json()

# 5. Dosya indir
def download_file(remote_path, local_path):
    data = {'remote_path': remote_path}
    response = requests.post(f"{BASE_URL}?action=download", data=data)
    return response.json()

# Kullanım örneği
if __name__ == "__main__":
    # Bağlantı kur
    result = connect_ftp("ftp.example.com", "user", "pass")
    print("Bağlantı:", result)
    
    # Disk kotasını kontrol et
    quota = check_quota()
    print("Disk Kotası:", quota)
    
    # Dosya yükle (eski dosyaları otomatik sil)
    upload_result = upload_file("test.txt", "/uploads/test.txt", auto_delete_old=True)
    print("Yükleme:", upload_result)
    if upload_result['success'] and upload_result['data']['deleted_old_files']:
        print("Silinen eski dosyalar:", upload_result['data']['deleted_old_files'])
    
    # Dosya listesi
    files = list_files("/")
    print("Dosyalar:", files)

Node.js Örnekleri

axios Kütüphanesi ile

const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');

// API Base URL
const BASE_URL = "http://your-domain.com/api.php";

// 1. Bağlantı kur
async function connectFTP(hostname, username, password) {
    try {
        const response = await axios.post(`${BASE_URL}?action=connect`, {
            hostname,
            username,
            password
        });
        return response.data;
    } catch (error) {
        console.error('Bağlantı hatası:', error.response.data);
        throw error;
    }
}

// 2. Dosya listesi al
async function listFiles(path = "/") {
    try {
        const response = await axios.get(`${BASE_URL}?action=list`, {
            params: { path }
        });
        return response.data;
    } catch (error) {
        console.error('Liste hatası:', error.response.data);
        throw error;
    }
}

// 3. Disk kotası kontrol et
async function checkQuota() {
    try {
        const response = await axios.get(`${BASE_URL}?action=quota`);
        return response.data;
    } catch (error) {
        console.error('Kota hatası:', error.response.data);
        throw error;
    }
}

// 4. Dosya yükle
async function uploadFile(filePath, remotePath = null) {
    try {
        if (!remotePath) {
            remotePath = `/${filePath.split('/').pop()}`;
        }
        
        const formData = new FormData();
        formData.append('file', fs.createReadStream(filePath));
        formData.append('remote_path', remotePath);
        
        const response = await axios.post(`${BASE_URL}?action=upload`, formData, {
            headers: formData.getHeaders()
        });
        return response.data;
    } catch (error) {
        console.error('Yükleme hatası:', error.response.data);
        throw error;
    }
}

// 5. Dosya indir
async function downloadFile(remotePath) {
    try {
        const response = await axios.post(`${BASE_URL}?action=download`, {
            remote_path: remotePath
        });
        return response.data;
    } catch (error) {
        console.error('İndirme hatası:', error.response.data);
        throw error;
    }
}

// Kullanım örneği
async function main() {
    try {
        // Bağlantı kur
        const connectResult = await connectFTP("ftp.example.com", "user", "pass");
        console.log("Bağlantı:", connectResult);
        
        // Disk kotasını kontrol et
        const quota = await checkQuota();
        console.log("Disk Kotası:", quota);
        
        // Dosya yükle
        const uploadResult = await uploadFile("test.txt", "/uploads/test.txt");
        console.log("Yükleme:", uploadResult);
        
        // Dosya listesi
        const files = await listFiles("/");
        console.log("Dosyalar:", files);
        
    } catch (error) {
        console.error("Hata:", error.message);
    }
}

main();

PHP Örnekleri

cURL ile

<?php
// API Base URL
$baseUrl = "http://your-domain.com/api.php";

// 1. Bağlantı kur
function connectFTP($hostname, $username, $password) {
    global $baseUrl;
    
    $data = [
        'hostname' => $hostname,
        'username' => $username,
        'password' => $password
    ];
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $baseUrl . '?action=connect');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    return json_decode($response, true);
}

// 2. Dosya listesi al
function listFiles($path = "/") {
    global $baseUrl;
    
    $url = $baseUrl . '?action=list&path=' . urlencode($path);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    return json_decode($response, true);
}

// 3. Disk kotası kontrol et
function checkQuota() {
    global $baseUrl;
    
    $url = $baseUrl . '?action=quota';
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    return json_decode($response, true);
}

// 4. Dosya yükle
function uploadFile($filePath, $remotePath = null) {
    global $baseUrl;
    
    if (!$remotePath) {
        $remotePath = "/" . basename($filePath);
    }
    
    $postData = [
        'remote_path' => $remotePath
    ];
    
    $cfile = new CURLFile($filePath);
    $postData['file'] = $cfile;
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $baseUrl . '?action=upload');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    return json_decode($response, true);
}

// 5. Dosya indir
function downloadFile($remotePath) {
    global $baseUrl;
    
    $data = [
        'remote_path' => $remotePath
    ];
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $baseUrl . '?action=download');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    return json_decode($response, true);
}

// Kullanım örneği
try {
    // Bağlantı kur
    $connectResult = connectFTP("ftp.example.com", "user", "pass");
    echo "Bağlantı: " . json_encode($connectResult, JSON_PRETTY_PRINT) . "\n";
    
    // Disk kotasını kontrol et
    $quota = checkQuota();
    echo "Disk Kotası: " . json_encode($quota, JSON_PRETTY_PRINT) . "\n";
    
    // Dosya yükle
    $uploadResult = uploadFile("test.txt", "/uploads/test.txt");
    echo "Yükleme: " . json_encode($uploadResult, JSON_PRETTY_PRINT) . "\n";
    
    // Dosya listesi
    $files = listFiles("/");
    echo "Dosyalar: " . json_encode($files, JSON_PRETTY_PRINT) . "\n";
    
} catch (Exception $e) {
    echo "Hata: " . $e->getMessage() . "\n";
}
?>

cURL Örnekleri

Windows Command Prompt

REM 1. Bağlantı kur
curl -X POST "http://your-domain.com/api.php?action=connect" ^
-H "Content-Type: application/x-www-form-urlencoded" ^
-d "hostname=ftp.example.com&username=user&password=pass"

REM 2. Disk kotası kontrol et
curl "http://your-domain.com/api.php?action=quota"

REM 3. Dosya listesi al
curl "http://your-domain.com/api.php?action=list&path=/uploads"

REM 4. Dosya yükle (eski dosyaları otomatik sil)
curl -X POST "http://your-domain.com/api.php?action=upload" ^
-F "file=@C:\path\to\file.txt" ^
-F "remote_path=/uploads/file.txt" ^
-F "auto_delete_old=true"

REM 5. Dosya indir
curl -X POST "http://your-domain.com/api.php?action=download" ^
-H "Content-Type: application/x-www-form-urlencoded" ^
-d "remote_path=/uploads/file.txt" ^
-o "downloaded_file.txt"

Linux/Mac Terminal

# 1. Bağlantı kur
curl -X POST "http://your-domain.com/api.php?action=connect" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "hostname=ftp.example.com&username=user&password=pass"

# 2. Disk kotası kontrol et
curl "http://your-domain.com/api.php?action=quota"

# 3. Dosya listesi al
curl "http://your-domain.com/api.php?action=list&path=/uploads"

# 4. Dosya yükle (eski dosyaları otomatik sil)
curl -X POST "http://your-domain.com/api.php?action=upload" \
-F "file=@/path/to/file.txt" \
-F "remote_path=/uploads/file.txt" \
-F "auto_delete_old=true"

# 5. Dosya indir
curl -X POST "http://your-domain.com/api.php?action=download" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "remote_path=/uploads/file.txt" \
-o "downloaded_file.txt"

Disk Kotası Kontrolü

API otomatik olarak disk kotası kontrolü yapar:

Disk Kotası Hatası Örneği:

{
  "success": false,
  "message": "Disk kotası %90'ın üzerinde. Yükleme yapılamaz.",
  "data": {
    "current_usage": "950.5 MB",
    "quota": "1 GB",
    "usage_percentage": 92.8
  },
  "timestamp": "2024-01-01 12:00:00"
}

Başarılı Kota Kontrolü:

{
  "success": true,
  "message": "Disk bilgileri alındı",
  "data": {
    "current_usage": "250.5 MB",
    "current_usage_formatted": "250.5 MB",
    "estimated_quota": 1073741824,
    "estimated_quota_formatted": "1 GB",
    "usage_percentage": 23.3,
    "file_count": 45,
    "system_info": "UNIX Type: L8",
    "current_path": "/"
  },
  "timestamp": "2024-01-01 12:00:00"
}