<?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"); // check connection
if ((!$conn_id) || (!$login_result)) {
echo "Ftp connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
die;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}// upload the file
$upload = ftp_put($conn_id, "$destination_file", "$source_file", FTP_BINARY); // check upload status
if (!$upload) {
echo "Ftp upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}// close the FTP stream
ftp_quit($conn_id);
?>
// 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"); // check connection
if ((!$conn_id) || (!$login_result)) {
echo "Ftp connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
die;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}// upload the file
$upload = ftp_put($conn_id, "$destination_file", "$source_file", FTP_BINARY); // check upload status
if (!$upload) {
echo "Ftp upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}// close the FTP stream
ftp_quit($conn_id);
?>
解决方案 »
- IT商业新闻网诚招PHP,SEO技术人员
- 请教:如何在PHP中使用socket+XML发送数据包?
- 高手帮忙修改一下类
- 关于PHP生成略缩图的疑问~(内祥)
- PHP4.x引入的9个超全局变量
- 昨天面试了,主管说给一个星期熟悉PHP和MYSQL,以前没有半点的了解。请高人指点兄弟如何在一星期熟悉这东东啊?
- 怎样在php中,将字符串ip转换成整数型的ip?
- 初学者问题,如何给print("s;dfjsf");中的字符串设定颜色
- JWT下如何统计每天用户登录数
- php中如何实现SELECT按照点选顺序显示选项
- 在win2000 SERVER中如何配制php?
- 谁有Vbullitin论坛的插件?如下列之一或多个,要多少分你说就行!
$username="用户名";
$password="用户密码";
$server="主机名";
$cdir="上传目录名" ;
//以上设置你的FTP主机名、用户名和用户密码
?〉
〈!-- 文件上传设置标签 --〉
〈form enctype="multipart/form-data" action=ftp.php method=post〉
〈!-- 传递变量 --〉
〈input type=hidden name=username value=〈? echo $username; ?〉〉
〈input type=hidden name=password value=〈? echo $password; ?〉〉
〈input type=hidden name=server value=〈? echo $server; ?〉〉
〈input type=hidden name=cdir value=〈? echo $cdir; ?〉〉
〈table〉
〈tr〉
〈td〉上传文件选择
〈input type=file name=upfile〉
〈/td〉
〈/tr〉
〈tr〉
〈td〉
〈!-- 提交表单 --〉
〈input type=submit name=action value=上传〉
〈/td〉
〈/tr〉
〈/table〉
〈/form〉处理上传文件:ftp.php 代码如下:〈?php
//ftp联接主机函数
function connect()
{
global $server, $username, $password;
$conn = ftp_connect($server);
ftp_login($conn, $username, $password);
return $conn;
}
//建立ftp联接
$result = connect();
if ($action == "上传")
{
//用来改变ftp路径
ftp_chdir($result, $cdir);
//用来上传指定的文件,同名并以二进制位传递
$res_code = ftp_put($result, $upfile_name, $upfile, FTP_BINARY);
// 判断是否正确上传
if ($res_code == 1)
echo "上传成功!";
else
echo "上传错误!";
}
// 关闭联接
ftp_quit($result);
?〉
$ftp_server="127.0.0.1";//假设Ftp Server的IP是127.0.0.1
$ftp_user_name="test";
$ftp_user_pass="test";//假设用户名和密码
$conn_id = ftp_connect("$ftp_server");
$login_result = ftp_login($conn_id, "$ftp_user_name", "$ftp_user_pass");
if((!$conn_id)||(!$login_result)) {
echo "Ftp connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
die;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
ftp_chdir ($conn_id,"/home");//切换目录到/home
$destination_file="test001.bin";
$source_file="c:/command.com";
//上面这一行应该用form来实现比较好一些
$upload = ftp_put($conn_id, "$destination_file", "$source_file", FTP_BINARY);
if (!$upload) {
echo "Ftp upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
ftp_quit($conn_id);
?>我改了楼上的贴子,加了几行,看看有没有帮助吧。