无需言 做自己 业 ,精于勤 荒于嬉.

FTP 函数 ftp_site 向服务器发送 SITE 命令

发表日期:2021-07-01 08:56:47 | 来源: | 分类:FTP 函数

      示例1
<?php 
// 连接 FTP 服务器$conn = ftp_connect('ftp.example.com');
if (!$conn) die('无法连接到 ftp.example.com');
// 使用用户 user 和密码 pass 登录服务器if (!ftp_login($conn, 'user', 'pass')) die('登录失败到 ftp.example.com');
// Issue: "SITE CHMOD 0600 /home/user/privatefile" command to ftp serverif (ftp_site($conn, 'CHMOD 0600 /home/user/privatefile')) {
   echo "命令执行成功。\n";
}
 else {
   die('命令执行失败。');
}
?>

阅读全文 »

FTP 函数 ftp_size 返回指定文件的大小

发表日期:2021-07-01 08:56:47 | 来源: | 分类:FTP 函数

      示例1
<?php 
$file = 'somefile.txt';
// 简单基本连接$conn_id = ftp_connect($ftp_server);
// 使用用户名和密码进行登录$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// 获取 $file 文件大小$res = ftp_size($conn_id, $file);
if ($res != -1) {
    echo "size of $file is $res bytes";
}
 else {
    echo "couldn't get the size";
}
// 关闭连接ftp_close($conn_id);
?>

阅读全文 »

FTP 函数 ftp_nb_put 存储一个文件至 FTP 服务器(non-blocking)

发表日期:2021-07-01 08:56:47 | 来源: | 分类:FTP 函数

      示例1
<?php 
// 初始化$ret = ftp_nb_put($my_connection, "test.remote", "test.local", FTP_BINARY);
while ($ret == FTP_MOREDATA) {
      // 可以同时干其它事   echo ".";
   // 继续上传...   $ret = ftp_nb_continue($my_connection);
}
if ($ret != FTP_FINISHED) {
   echo "上传过程中发生错误...";
   exit(1);
}
?>

      示例2
<?php 
// 初始化$ret = ftp_nb_put($my_connection, "test.remote", "test.local",                       FTP_BINARY, ftp_size("test.remote"));
// 另一种写法: $ret = ftp_nb_put($my_connection, "test.remote", "test.local", //                           FTP_BINARY, FTP_AUTORESUME);
while ($ret == FTP_MOREDATA) {
      // 可以同时干其它事情   echo ".";
   // 继续上传...   $ret = ftp_nb_continue($my_connection);
}
if ($ret != FTP_FINISHED) {
   echo "上传过程中发生错误...";
   exit(1);
}
?>

阅读全文 »

FTP 函数 ftp_systype 返回远程 FTP 服务器的操作系统类型

发表日期:2021-07-01 08:56:47 | 来源: | 分类:FTP 函数

      示例1
<?php 
// 建立 ftp 连接$ftp = ftp_connect('ftp.example.com');
ftp_login($ftp, 'user', 'password');
// 获取操作系统类型if ($type = ftp_systype($ftp)) {
    echo "Example.com 的操作系统为 $type\n";
}
 else {
    echo "无法获取操作系统类型";
}
?>

阅读全文 »

FTP 函数 ftp_rmdir 删除目录

发表日期:2021-07-01 08:56:47 | 来源: | 分类:FTP 函数

      示例1
<?php 
$dir = 'www/';
// 简单基本连接$conn_id = ftp_connect($ftp_server);
// 使用用户名和密码进行登录$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// 尝试删除 $dir 目录if (ftp_rmdir($conn_id, $dir)) {
    echo "Successfully deleted $dir\n";
}
 else {
    echo "There was a problem while deleting $dir\n";
}
ftp_close($conn_id);
?>

阅读全文 »

FTP 函数 ftp_ssl_connect 打开 SSL-FTP 连接

发表日期:2021-07-01 08:56:47 | 来源: | 分类:FTP 函数

      示例1
<?php 
// 建立基础 SSL 连接$conn_id = ftp_ssl_connect($ftp_server);
// 使用用户名和密码登录$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (!$login_result) {
    // 在这种情况下,PHP 会发生 E_WARNING 级别的告警消息    die("can't login");
}
echo ftp_pwd($conn_id);
 // /// 关闭 ssl 连接ftp_close($conn_id);
?>

阅读全文 »

FTP 函数 ftp_close 关闭一个 FTP 连接

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
// set up basic connection$conn_id = ftp_connect($ftp_server);
// login with username and password$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// print the current directoryecho ftp_pwd($conn_id);
 // /// close this connectionftp_close($conn_id);
?>

阅读全文 »

FTP 函数 ftp_connect 建立一个新的 FTP 连接

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
$ftp_server = "ftp.example.com";
// set up a connection or die$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
 ?>

阅读全文 »

FTP 函数 ftp_delete 删除 FTP 服务器上的一个文件

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
$file = 'public_html/old.txt';
// set up basic connection$conn_id = ftp_connect($ftp_server);
// login with username and password$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to delete $fileif (ftp_delete($conn_id, $file)) {
 echo "$file deleted successful\n";
}
 else {
 echo "could not delete $file\n";
}
// close the connectionftp_close($conn_id);
?>

阅读全文 »

FTP 函数 ftp_exec 在 FTP 服务器运行指定的命令

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
// variable initialization$command = 'ls -al >files.txt';
// set up basic connection$conn_id = ftp_connect($ftp_server);
// login with username and password$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// execute commandif (ftp_exec($conn_id, $command)) {
    echo "$command executed successfully\n";
}
 else {
    echo "could not execute $command\n";
}
// close the connectionftp_close($conn_id);
?>

阅读全文 »

FTP 函数 ftp_fput 上传一个已经打开的文件到 FTP 服务器

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
// open some file for reading$file = 'somefile.txt';
$fp = fopen($file, 'r');
// set up basic connection$conn_id = ftp_connect($ftp_server);
// login with username and password$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to upload $fileif (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
    echo "Successfully uploaded $file\n";
}
 else {
    echo "There was a problem while uploading $file\n";
}
// close the connection and the file handlerftp_close($conn_id);
fclose($fp);
?>

阅读全文 »

FTP 函数 ftp_fget 从 FTP 服务器上下载一个文件并保存到本地一个已经打开的文件中

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
// path to remote file$remote_file = 'somefile.txt';
$local_file = 'localfile.txt';
// open some file to write to$handle = fopen($local_file, 'w');
// set up basic connection$conn_id = ftp_connect($ftp_server);
// login with username and password$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $remote_file and save it to $handleif (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) {
 echo "successfully written to $local_file\n";
}
 else {
 echo "There was a problem while downloading $remote_file to $local_file\n";
}
// close the connection and the file handlerftp_close($conn_id);
fclose($handle);
?>

阅读全文 »

FTP 函数 ftp_login 登录 FTP 服务器

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
                     $ftp_server = "ftp.example.com";
$ftp_user = "foo";
$ftp_pass = "bar";
// 设置一个连接或失败时退出$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
 // 尝试登录if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    echo "Connected as $ftp_user@$ftp_server\n";
}
 else {
    echo "Couldn't connect as $ftp_user\n";
}
// 关闭连接ftp_close($conn_id);
  ?>

阅读全文 »

FTP 函数 ftp_get 从 FTP 服务器上下载一个文件

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
// define some variables$local_file = 'local.zip';
$server_file = 'server.zip';
// set up basic connection$conn_id = ftp_connect($ftp_server);
// login with username and password$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_fileif (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
}
 else {
    echo "There was a problem\n";
}
// close the connectionftp_close($conn_id);
?>

阅读全文 »

FTP 函数 ftp_mkdir 建立新目录

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
$dir = 'www';
// set up basic connection$conn_id = ftp_connect($ftp_server);
// login with username and password$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to create the directory $dirif (ftp_mkdir($conn_id, $dir)) {
 echo "successfully created $dir\n";
}
 else {
 echo "There was a problem while creating $dir\n";
}
// close the connectionftp_close($conn_id);
?>

阅读全文 »

FTP 函数 ftp_mdtm 返回指定文件的最后修改时间

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
$file = 'somefile.txt';
// set up basic connection$conn_id = ftp_connect($ftp_server);
// login with username and password$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//  get the last modified time$buff = ftp_mdtm($conn_id, $file);
if ($buff != -1) {
    // somefile.txt was last modified on: March 26 2003 14:16:41.    echo "$file was last modified on : " . date("F d Y H:i:s.", $buff);
}
 else {
    echo "Couldn't get mdtime";
}
// close the connectionftp_close($conn_id);
?>

阅读全文 »

FTP 函数 ftp_get_option 返回当前 FTP 连接的各种不同的选项设置

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
// Get the timeout of the given FTP stream$timeout = ftp_get_option($conn_id, FTP_TIMEOUT_SEC);
?>

阅读全文 »

FTP 函数 ftp_mlsd 返回指定目录中的文件列表

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
// 简单基本连接$conn_id = ftp_connect($ftp_server);
// 使用用户名和密码进行登录$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// 获取当前目录的内容$contents = ftp_mlsd($conn_id, ".");
// 输出 $contentsvar_dump($contents);
?>

阅读全文 »

FTP 函数 ftp_nb_fput 将文件存储到 FTP 服务器 (非阻塞)

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
$file = 'index.php';
$fp = fopen($file, 'r');
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// 初始化上传$ret = ftp_nb_fput($conn_id, $file, $fp, FTP_BINARY);
while ($ret == FTP_MOREDATA) {
   // 任何其他需要做的操作   echo ".";
   // 继续上传...   $ret = ftp_nb_continue($conn_id);
}
if ($ret != FTP_FINISHED) {
   echo "There was an error uploading the file...";
   exit(1);
}
fclose($fp);
?>

阅读全文 »

FTP 函数 ftp_nb_fget 从 FTP 服务器获取文件并写入到一个打开的文件(非阻塞)

发表日期:2021-07-01 08:56:46 | 来源: | 分类:FTP 函数

      示例1
<?php 
// 打开要写入的文件$file = 'index.php';
$fp = fopen($file, 'w');
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// 初始化下载$ret = ftp_nb_fget($conn_id, $fp, $file, FTP_BINARY);
while ($ret == FTP_MOREDATA) {
   // 其他要做的工作   echo ".";
   // 继续下载...   $ret = ftp_nb_continue($conn_id);
}
if ($ret != FTP_FINISHED) {
   echo "There was an error downloading the file...";
   exit(1);
}
// 关闭文件句柄fclose($fp);
?>

阅读全文 »

全部博文(1589)
集速网 copyRight © 2015-2025 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。