Skip to content

Instantly share code, notes, and snippets.

@OzzyCzech OzzyCzech/ftp.php
Created May 29, 2011

Embed
What would you like to do?
FTP Connection
<?php
/**
* Generuje ID FTP pripojeni na zaklade zadane URL
* ftp://username:password@sld.domain.tld:21/path1/path2/
*/
function getFtpConnection($uri)
{
preg_match("/(?P<protocol>ftps?:\/\/)(?P<username>.*?):(?P<password>.*?)@(?P<url>.*?):?(?P<port>[1-9]+)?(?<dir>\/.*)/i", $uri, $match);
$conn = ftp_connect($match['url'], empty($match['port']) ? 21 : (int)$match['port']) or die("Couldn't connect to " . $match['url']);
if (ftp_login($conn, $match['username'], $match['password']))
{
ftp_chdir($conn, $match['dir']);
return $conn;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.