|
-
Apr 24th, 2007, 01:58 PM
#2
Re: Uploading files on server
well. the way you're checking the status of uploaded files is.. wrong? you are redefining $upload for every file found, so you're technically only checking if the last file in your matched list was a success or not.
you're also not defining $curdir, so you technically aren't uploading it to anywhere. however, even if you were defining $curdir, it would be incorrect. you need to supply a destination filename (not a destination directory) when you're setting the remote_path with ftp_put().
this is my modified and rewritten version of your script -- it gives a bit more detailed output as it goes along and will tell you exactly which files failed to upload.
PHP Code:
<pre>
<?php
function timestamp(){
return "\r\n" . '[' . date('H:i') . '] -> ';
}
set_time_limit(0);
//server information
$ftp = array();
$ftp['server'] = 'ftp.domain.tld';
$ftp['port'] = 21;
$ftp['user'] = 'username';
$ftp['pass'] = 'password';
//attempt to connect and login
$conn = @ftp_connect($ftp['server'], $ftp['port']);
$login = @ftp_login($conn, $ftp['user'], $ftp['pass']);
//did we connect?
if($conn && $login) {
echo timestamp() . "succesfully connected to {$ftp['user']}@{$ftp['server']}:{$ftp['port']}";
}else{
echo timestamp() . "failed to connect to {$ftp['user']}@{$ftp['server']}:{$ftp['port']}";
exit;
}
//turn on passive mode if you need it
ftp_pasv($conn, true);
if(ftp_chdir($conn, 'public_http')){
echo timestamp() . 'moved to ' . ftp_pwd($conn);
}else{
echo timestamp() . 'failed to change directory';
}
//list out our currently directory
echo "\n\n";
print_r(ftp_rawlist($conn, '/' . ftp_pwd($conn) . '/'));
//we want to upload every php file in the root directory
$ftp['uploads'] = glob('e:/root/*.php');
foreach($ftp['uploads'] as $localpath){
//we need the filename of each $localpath ONLY
$remotepath = substr($localpath, strrpos($localpath, '/') + 1, strlen($localpath));
$upload = ftp_put($conn, $remotepath, $localpath, FTP_ASCII);
echo timestamp() . 'upload of "' . $localpath . '" to "' . $remotepath . '" -- status=';
if(!$upload){
echo '<strong><span style="color: #f00;">FAILED</span></strong>';
}else{
echo '<strong><span style="color: #0f0;">COMPLETED</span></strong>';
}
}
//disconnect
ftp_close($conn);
echo timestamp() . "disconnected";
?>
</pre>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|