/    Sign up×
Community /Pin to ProfileBookmark

need help to upload my directory to ftp server

i need help to upload my directry to ftp server and then i want after uploading remove the directroy from my comuter
i have following program but it is not properly working..
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
form
<form method=”post” action=”upload.php”>

Move or Upload Folder Using PHP FTP Functions<br />

</p>
<table width=”373″ border=”1″>
<tr>
<td width=”184″>server address </td>
<td width=”173″><input type=”text” id=”server_name” name=”server_name” /></td>
</tr>
<tr>
<td>user name </td>
<td><input type=”text” name=”user_name” id=”user_name” /></td>
</tr>
<tr>
<td>user password</td>
<td><input type=”text” id=”user_password” name=”user_password” /></td>
</tr>
<tr>
<td>local directory</td>
<td><input type=”text” name=”local_dir” id=”local_dir” /></td>
</tr>
<tr>
<td>remote directory</td>
<td><input type=”text” name=”remote_dir” id=”remote_dir” /></td>
</tr>
<tr>
<td><input name=”upload” type=”submit” id=”upload” /></td>
<td>&nbsp;</td>
</tr>
</table>
<p>&nbsp; </p>
</form>

………………
code
………..
?php
// Start the session
session_start();
header(“Cache-control: private”); //IE 6 Fix

$_server = $_POST[“server_name”];
$_user_name = $_POST[“user_name”];
$_user_pass = $_POST[“user_password”];
$local_dir = $_POST[“local_dir”];
$remote_dir = $_
POST[“remote_dir”];

require (“uploadfunctionpage.php”);

$uploadfunction = moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir);

if($uploadfunction=true)
{
echo ” successfull”;
}
else{
echo “failed”;
}

and

function
………………

<?php

//Move or Upload Folder Using PHP FTP Functions

function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) {

//$ftp_server = “hostname”;
//$ftp_user = “username”;
//$ftp_pass = “password”;

// set up a connection or die

echo”$_user_name”;
echo”$_
user_pass”;
echo” dire === “;
echo”$local_dir”;
echo”$remote_dir”;

//$_conn_id = ftp_connect($_server) or die(“Couldn’t connect to $ftp_server”);

// try to login
//if (ftp_login($conn_id, $_user_name, $_user_pass)) {
//echo “Connected as $_user_name@$_servern”;
//$result = true;
//}
// else
// {
//echo “Couldn’t connect as $_user_namen”;
//$result = false;
//}

// set up basic connection
$_conn_id = ftp_connect($_server);

// login with username and password
$_login_result = ftp_login($_conn_id, $_user_name, $_user_pass);

// check connection
if ((!$_conn_id) || (!$_login_result)) {
$_error = “FTP connection has failed!”;
$_
error .= “Attempted to connect to $_server for user $_user_name”;
$result = false;
} else {
$_error = “Connected to $_server, for user $_user_name”;
}

$conn_id = $_conn_id;

@ftp_mkdir($conn_id, $remote_dir);
$handle = opendir($local_dir);
while (($file = readdir($handle)) !== false) {
if (($file != ‘.’) && ($file != ‘..’)) {
if (is_dir($local_dir . $file)) {
//recursive call
moveFolder($conn_id, $local_dir . $file . ‘/’, $remote_dir . $file . ‘/’);
} else
$f[] = $file;
}
}

closedir($handle);
if (count($f)) {
sort($f);
@ftp_chdir($conn_id, $remote_dir);
foreach ($f as $files) {
$from = @fopen(“$local_dir$files”, ‘r’);
$moveFolder = ftp_fput($conn_id, $files, $from, FTP_BINARY);

// check upload status
if (!$moveFolder) {
$this->_error = “FTP upload has failed! From:” . $local_dir . ” To: ” . $remote_dir;
$result = false;
} else {
$this->_
error = “Uploaded $local_dir to $remote_dir as $this->_server”;
$result = true;
}
}
}
return $result;
}
?>

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@asifkamalzahidauthorNov 19.2008 — the main problom is, when i puting the name of my local server then it is not reading,code is ok but wwhy it is not accessing my dierectory.

may be i have problom with syntax to define the local directory.

becouse for file in when making its type "type=file" but i dont know what i can make the type for directory in the form. i reciveing the following error

...................

errro[color=#BF0000][/color]

Warning: opendir(/c/php) [function.opendir]: failed to open dir: No such file or directory in G:WEBROOTwilbournftptestuploadfunctionpage.php on line 57

Warning: readdir(): supplied argument is not a valid Directory resource in G:WEBROOTwilbournftptestuploadfunctionpage.php on line 58

Warning: closedir(): supplied argument is not a valid Directory resource in G:WEBROOTwilbournftptestuploadfunctionpage.php on line 68

Notice: Undefined variable: f in G:WEBROOTwilbournftptestuploadfunctionpage.php on line 69

Notice: Undefined variable: result in G:WEBROOTwilbournftptestuploadfunctionpage.php on line 86

successfullPHP Warning: opendir(/c/php) [function.opendir]: failed to open dir: No such file or directory in G:WEBROOTwilbournftptestuploadfunctionpage.php on line 57 PHP Warning: readdir(): supplied argument is not a valid Directory resource in G:WEBROOTwilbournftptestuploadfunctionpage.php on line 58 PHP Warning: closedir(): supplied argument is not a valid Directory resource in G:WEBROOTwilbournftptestuploadfunctionpage.php on line 68 PHP Notice: Undefined variable: f in G:WEBROOTwilbournftptestuploadfunctionpage.php on line 69 PHP Notice: Undefined variable: result in G:WEBROOTwilbournftptestuploadfunctionpage.php on line 86 .
×

Success!

Help @asifkamalzahid spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...