You can access an FTP server via QuotaGuard Static from your PHP application so that your traffic always appears to come from the same IP address. This solution uses PHP cURL and our SOCKS5 proxy which is accessible on port 1080:


Using with an unauthenticated FTP Server

 

<?php
   $quotaguard_env = getenv("QUOTAGUARDSTATIC_URL");
   $quotaguard = parse_url($quotaguard_env);
   $proxyUrl       = $quotaguard['host'].":1080";
   $proxyAuth       = $quotaguard['user'].":".$quotaguard['pass']; 
   print $proxyUrl; 
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL,"ftp://ftp.gnu.org");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_PROXY, $proxyUrl);
    curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyAuth);
	curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);

    $result = curl_exec ($curl);
    curl_close ($curl);
    print $result;
?>

 

Using with an authenticated FTP Server

If your FTP server requires a username and password you just need to set the extra CURLOPT_USERPWD parameter.


 

<?php
   $username = "myftpuser";
   $password = "myftppw";
   $quotaguard_env = getenv("QUOTAGUARDSTATIC_URL");
   $quotaguard = parse_url($quotaguard_env);
   $proxyUrl       = $quotaguard['host'].":1080";
   $proxyAuth       = $quotaguard['user'].":".$quotaguard['pass']; 
   print $proxyUrl; 
    $curl = curl_init();
    // This example will not work with this FTP server as it does not require username/password!
    curl_setopt($curl, CURLOPT_URL,"ftp://ftp.gnu.org");
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl, CURLOPT_PROXY, $proxyUrl);
    curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyAuth);
    curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);

    $result = curl_exec ($curl);
    curl_close ($curl);
    print $result;
?>