PHP ftp_put失败,并显示“Warning:ftp_put():PORT command successful” [英] PHP ftp_put fails with "Warning: ftp_put (): PORT command successful"

查看:1399
本文介绍了PHP ftp_put失败,并显示“Warning:ftp_put():PORT command successful”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件在FTP服务器上创建,但其始终为0字节。请给我一个解决方案,以便文件上传将工作成功。



警告:ftp_put():PORT($ p
$ b

命令成功在第30行的C:\ xampp \ htdocs \ mailing \ teskirim-file-simpan2.php中 -
FTP上传失败!




我的脚本是:

 <?php 
$ ftp_server =**** ****;
$ ftp_serverpath =ftp。。$ ftp_server;
$ ftp_user_name =********;
$ ftp_user_pass =***********;
$ email_dir =******* @ *********;

$ nyambungkeftp = ftp_connect($ ftp_server);
if(false === $ nyambungkeftp){
抛出新的异常('Unable to connect');
}

$ loggedInnyambungkeftp = ftp_login($ nyambungkeftp,$ ftp_user_name,$ ftp_user_pass);
if(true === $ loggedInnyambungkeftp){
echo'Success!';
} else {
抛出新的异常('无法登录'); $(b


if((!!nyambungkeftp)||(!$ loggedInnyambungkeftp)){
echoFTP连接失败!
echo尝试连接到用户$ ftp_user_name的$ ftp_server;
出口;
} else {
echo连接到$ ftp_server,用户$ ftp_user_name;
}

//上传文件
$ dest ='detectip.txt';
$ source ='C:\xampp\htdocs\persuratan\file2\detectip.txt';

echo $ dest;
echo $ source;
$ upload = ftp_put($ nyambungkeftp,$ dest,$ source,FTP_ASCII);


//检查上传状态
if(!$ upload){
echoFTP upload has failed!;
} else {
echo上传$ source_file到$ ftp_server作为$ destination_file;
}

//关闭FTP流
ftp_close($ nyambungkeftp);

?>


解决方案

PHP默认为活动的FTP模式。由于无处不在的防火墙/ NAT /代理,主动模式几乎无法运行。

几乎总是需要使用被动模式。



对于该呼叫, ftp_login 后的> ftp_pasv

  ftp_pasv($ nyambungkeftp,true); 

请参阅 my .net / eng / docs / ftp_modesrel =nofollow noreferrer> FTP连接模式,了解为什么您通常需要使用被动模式。


File is created on the FTP server, but its always 0 bytes large. Please give me a solution so that the file upload will working success.

I keep getting this warning:

Warning: ftp_put (): PORT command successful in C: \ xampp \ htdocs \ mailing \ teskirim-file-simpan2.php on line 30
FTP upload has failed!

My script is:

<?php
$ftp_server = "********";
$ftp_serverpath = "ftp.".$ftp_server;
$ftp_user_name = "********";
$ftp_user_pass = "***********";
$email_dir = "*******@*********";

$nyambungkeftp = ftp_connect($ftp_server);
if (false === $nyambungkeftp) {
    throw new Exception('Unable to connect');
}

$loggedInnyambungkeftp = ftp_login($nyambungkeftp,  $ftp_user_name,  $ftp_user_pass);
if (true === $loggedInnyambungkeftp) {
    echo 'Success!';
} else {
    throw new Exception('Unable to log in');
}

if ((!$nyambungkeftp) || (!$loggedInnyambungkeftp)) { 
        echo "FTP connection has failed!";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
        exit; 
    } else {
        echo "Connected to $ftp_server, for user $ftp_user_name";
    }

// upload the file
$dest = 'detectip.txt';
$source = 'C:\xampp\htdocs\persuratan\file2\detectip.txt';

echo $dest;
echo $source;
$upload = ftp_put($nyambungkeftp, $dest, $source, FTP_ASCII); 


// 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_close($nyambungkeftp); 

?>

解决方案

PHP defaults to the active FTP mode. The active mode hardly ever works these days due to ubiquitous firewalls/NATs/proxies.

You almost always need to use the passive mode.

For that call the ftp_pasv after the ftp_login:

ftp_pasv($nyambungkeftp, true);

See my article on FTP connection modes, to understand, why you typically need to use the passive mode.

这篇关于PHP ftp_put失败,并显示“Warning:ftp_put():PORT command successful”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆