On April 1, 2021, we are moving all of our QuotaGuard Support Documentation to 


https://quotaguard.github.io/qg-docs/


 Please Update Your Support Bookmarks


 Documentation for this article will be maintained at 


https://quotaguard.github.io/qg-docs/quickstart-ruby 


Please click on the above link to ensure you are reading 

the most recent and updated documentation.


You can access an FTP server via QuotaGuard 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("QUOTGUARD_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("QUOTAGUARD_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;
?>

If you have questions, or if this solution doesn’t work or fit your use case, please reach out to us at Support so we can help figure it out with you.


Working with sensitive data, like HIPAA, Financial, or Personally Identifiable Information (PII)? 
    Then you will want to check out our QuotaGuard Shield solution, it's the same as QuotaGuard Static, but with stronger end to end security for your requests. We can also help migrate current Static customers to Shield for free, just reach out to us at Support to request assistance.