Code Duplication    Length = 14-15 lines in 3 locations

Sources/PackageGet.php 1 location

@@ 122-136 (lines=15) @@
119
120
	if ($context['package_download_broken'])
121
	{
122
		if (isset($_POST['ftp_username']))
123
		{
124
			require_once($sourcedir . '/Class-Package.php');
125
			$ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
126
127
			if ($ftp->error === false)
128
			{
129
				// I know, I know... but a lot of people want to type /home/xyz/... which is wrong, but logical.
130
				if (!$ftp->chdir($_POST['ftp_path']))
131
				{
132
					$ftp_error = $ftp->error;
133
					$ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path']));
134
				}
135
			}
136
		}
137
138
		if (!isset($ftp) || $ftp->error !== false)
139
		{

Sources/Subs-Package.php 1 location

@@ 1023-1037 (lines=15) @@
1020
		$files = packageRequireFTP($destination_url, $files, $return);
1021
		return $files;
1022
	}
1023
	elseif (isset($_POST['ftp_username']))
1024
	{
1025
		require_once($sourcedir . '/Class-Package.php');
1026
		$ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
1027
1028
		if ($ftp->error === false)
1029
		{
1030
			// Common mistake, so let's try to remedy it...
1031
			if (!$ftp->chdir($_POST['ftp_path']))
1032
			{
1033
				$ftp_error = $ftp->last_message;
1034
				$ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path']));
1035
			}
1036
		}
1037
	}
1038
1039
	if (!isset($ftp) || $ftp->error !== false)
1040
	{

other/install.php 1 location

@@ 596-609 (lines=14) @@
593
594
		$incontext['ftp_errors'] = array();
595
		require_once('Sources/Class-Package.php');
596
		if (isset($_POST['ftp_username']))
597
		{
598
			$ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
599
600
			if ($ftp->error === false)
601
			{
602
				// Try it without /home/abc just in case they messed up.
603
				if (!$ftp->chdir($_POST['ftp_path']))
604
				{
605
					$incontext['ftp_errors'][] = $ftp->last_message;
606
					$ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path']));
607
				}
608
			}
609
		}
610
611
		if (!isset($ftp) || $ftp->error !== false)
612
		{