Page 1 of 1

One click script upload

Posted: Wed Mar 23, 2011 7:45 pm
by Danny7211
Hi there,

I'm new to this forum so I apologize in advance if I'm posting this topic within the wrong category.

I am looking to have a script on a server where a user would be able to visit my website, fill in their FTP details and the PHP script would be uploaded to their account. For example: I have a PHP script and would make it easier for users to upload it to their shared hosting/vps/server without having them to download it to their PC, so they can visit my website, enter their FTP details and the script would be uploaded for them.

I'm wondering if anything along these lines exists or is it something I'm going to hire a freelancer to do?

Any help is appreciated,
Danny.

Re: One click script upload

Posted: Thu Mar 24, 2011 5:49 am
by vishal_arora
Hello Danny,
It is easy to upload script to ftp via ftp_put function provided by php

Re: One click script upload

Posted: Thu Mar 24, 2011 8:13 am
by Danny7211
Hi,

Thanks for your reply, I've made a test FTP script to see if I can do it but I'm recieving some errors, here is a screenshot: http://i52.tinypic.com/xc225h.jpg

Here is the code that I have created; index.html

Code: Select all

<html>
<head>
<title> PHP FTP Upload Test </title>
</head>
<body>
<table>
<form method="post" action="ftp.php" enctype="multipart/form-data">
<tr>
<td>Username:</td>
<td><input type="text" name="username" size="30"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" size="30"></td>
</tr>
<tr>
<td>File:</td>
<td><input type="file" name="File_1" size="30"></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="Submit"></td>
</tr>
</form>
</table>
</body>
</html>
ftp.php

Code: Select all

<?php

// FTP Configuration
$FTP_User = "$username";
$FTP_Pass = "$password";
$FTP_Host = "127.0.0.1";
$FTP_Root = "/";

if (isset($action) && $action == "submit") 
{

$Connect = ftp_connect($FTP_Host);

if (!$Connect)
{
echo "Error: Could not connect to ftp server<br>";
exit;
}

echo "Connected to $FTP_Host<br>";

$login = ftp_login($Connect, $FTP_User, $FTP_Pass);

$passive = ftp_pasv ($Connect, true );

echo "Current directory is now: " . ftp_pwd($Connect) . "<br>";

if (ftp_chdir($Connect, "$FTP_Root")) 
{
echo "Current directory is now: " . ftp_pwd($Connect) . "<br>";
} else echo "Cannot change directory"; 

$contents = ftp_nlist($Connect, ".");

print_r($contents) . "<br>"; 

if (!passive){
echo "Failed to enter passive mode.<br>";
}
else {
echo "Entered passive mode.<br>";
}

if (!$login)
{
echo "Error: Could not log on as $FTP_User<br>";
ftp_quit($Connect);
exit;
}

echo "Logged in as $FTP_User<br>";

$Filename = $FTP_Root . $_FILES['File_1']['name'];


if (file_exists($Filename))
{
echo "The file $Filename exists<BR>";
}
else
{
echo "The file $Filename does not exist<BR>";
}

$Local_Resource = $_FILES['File_1']['tmp_name'];

$upload = ftp_put($Connect, '$Filename', '$Local_Resource', FTP_BINARY);

if (!$upload)
{
echo "There was a problem uploading $Local_Resource to $Filename";
}
else
{
echo "Successfully uploaded $Filename";
}
ftp_quit($Connect);
}

?>
Sorry if it seems like I'm being a pain, I'm just not that experienced in PHP.

Re: One click script upload

Posted: Thu Mar 24, 2011 1:05 pm
by McInfo
Who is the intended audience for this script? I'm not convinced that someone would compromise their FTP account to save a few mouse clicks, especially if they have to type in credentials that are probably already remembered by their FTP client application.

To address your error messages, read Variables From External Sources.