note 68915 added to ref.ftp
| From: | nicklas at programmera dot nu | Date: | Tue, 15 Aug 2006 21:56:36 +0000 |
| Subject: | note 68915 added to ref.ftp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115954@lists.php.net to get a copy of this message | ||
I didn't quite like my FTP program since I had to make all the settings all over when i
restarted the client, so I made this script for simple ftp uploading, its running as a CLI app.
<?php
//if STDIN isn't defined, define it
if (!defined("STDIN"))
{
define("STDIN", fopen("php://stdin", "r"));
}
echo "FTP file uploader\r\n\r\n";
echo "Server: ";
//trim() all the fgets cause it seams to add a \n
$server = trim(fgets(STDIN));
echo "Username: ";
$username = trim(fgets(STDIN));
echo "Password: ";
$password = trim(fgets(STDIN));
$connect = ftp_connect($server);
$login = ftp_login($connect, $username, $password);
if ((!$connect) || (!$login))
{
exit("Login failed.\r\n");
}
echo "Connected\r\n";
echo "PASV (Y/Any key = Off): ";
if(trim(fgets(STDIN)) == "Y")
{
//enable passive mode
ftp_pasv($connect, true);
echo "PASV: On\r\n";
}
else
{
echo "PASV: Off\r\n";
}
$showContent = ftp_nlist($connect, "");
echo "Listing Contents:\r\n";
var_dump($showContent);
echo "File to upload: ";
$file = trim(fgets(STDIN));
//escape the uploading process by typing "exit;"
if ($file == "exit;")
{
exit;
}
//use "$file, $file" since the file shouldn't be renamed, also if its a binary file
change the last argument to FTP_BINARY
$upload = ftp_put($connect, $file, $file, FTP_ASCII);
if (!$upload)
{
exit("Upload failed.\r\n");
}
else
{
echo "The file \"" . $file . "\" was successfully uploaded. :)\r\nSize of
\"" . $file . "\": " . filesize($file) / 1024 ."kb.\r\n";
echo "My work is done, bye.\r\n";
}
ftp_close($connect);
?>
----
Server IP: 193.27.201.10 (proxied: 193.27.201.10 1.0 www1.shellkonto.se:3128 (squid/2.5.STABLE4))
Probable Submitter: 81.224.236.77
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/ref.ftp.php
Edit -- https://master.php.net/note/edit/68915
Del: integrated -- https://master.php.net/note/delete/68915/integrated
Del: useless -- https://master.php.net/note/delete/68915/useless
Del: bad code -- https://master.php.net/note/delete/68915/bad+code
Del: spam -- https://master.php.net/note/delete/68915/spam
Del: non-english -- https://master.php.net/note/delete/68915/non-english
Del: in docs -- https://master.php.net/note/delete/68915/in+docs
Del: other reasons-- https://master.php.net/note/delete/68915
Reject -- https://master.php.net/note/reject/68915
Search -- https://master.php.net/manage/user-notes.php