Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

file upload - PHP ftp_put fails

I upload XML file through FTP:

$ftp = "ftp";
$username = "username";
$pwd = "password";
$filename = $_FILES[$xyz][$abc];
$tmp = $_FILES['file']['tmp_name'];
$destination = "/Content/EnquiryXML ";

$connect = ftp_connect($ftp)or die("Unable to connect to host");
ftp_login($connect,$username,$pwd)or die("Authorization Failed");
echo "Connected!<br/>";              

if(!$filename)
{
    echo"Please select a file";
}

else
{
    ftp_put($connect,$destination.'/'.$filename,$tmp,FTP_ASCII)or die("Unable to upload");
    echo"File successfully uploaded to FTP";
}

I want to send the XML file created using DOMDocument to a FTP server but I am not able.

The ftp_put returns false.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Most typical cause of problems with ftp_put (or any other transfer command like ftp_get, ftp_nlist, ftp_rawlist, ftp_mlsd) is that PHP defaults to the active mode. And in 99% cases, one has to switch to the passive mode, to make the transfer working. Use the ftp_pasv function.

$connect = ftp_connect($ftp) or die("Unable to connect to host");
ftp_login($connect, $username, $pwd) or die("Authorization failed");
// turn passive mode on
ftp_pasv($connect, true) or die("Unable switch to passive mode");

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...