分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

yii2 ftp 的常规操作 上传 下载

发布时间:2023-09-06 01:35责任编辑:傅花花关键词:暂无标签
<?phpfunction make_directory($ftp_stream, $dir){ ?// if directory already exists or can be immediately created return true ?if (ftp_is_dir($ftp_stream, $dir) || @ftp_mkdir($ftp_stream, $dir)) return true; ?// otherwise recursively try to make the directory ?if (!make_directory($ftp_stream, dirname($dir))) return false; ?// final step to create the directory ?return ftp_mkdir($ftp_stream, $dir);} ?function ftp_is_dir($ftp_stream, $dir){ ?// get current directory ?$original_directory = ftp_pwd($ftp_stream); ?// test if you can change directory to $dir ?// suppress errors in case $dir is not a file or not a directory ?if ( @ftp_chdir( $ftp_stream, $dir ) ) { ???// If it is a directory, then change the directory back to the original directory ???ftp_chdir( $ftp_stream, $original_directory ); ???return true; ?} else { ???return false; ?}}$path = ‘fptfiles‘;//ftp服务器下的目录$putFilePath = ‘D:\ftpfiles\attack.txt‘; // 本地上传的文件路径$conn = ftp_connect("ftpIpAddress") or die("Could not connect");ftp_login($conn,"username","pwd");//利用ftp创建目录make_directory($conn,$path);//利用ftp选择进入目录ftp_chdir($conn,$path);//开始上传 ?上传到了 ftp根目录下 fptfiles/attack.txtif(ftp_put($conn, ‘attack.txt‘, ?$putFilePath , FTP_ASCII)){ ????echo ?‘put success‘;}else{ ???echo ?‘put fail‘;}$getFilePath = ‘D:\ftpfiles\attackget.txt‘;// 本地下载的文件路径//ftp 下载if(ftp_get($conn, $getFilePath, ?‘attack.txt‘, FTP_ASCII)){ ???echo ?‘get success‘;}else{ ???echo ?‘get fail‘;}ftp_close($conn);//注意上传端的ftp权限设置

yii2 ftp 的常规操作 上传 下载

原文地址:https://www.cnblogs.com/Rampage/p/8244573.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved