PHP's ftp_put operation failed
P粉884548619
2023-08-24 22:05:13
<p>I upload the XML file via FTP: </p>
<pre class="brush:php;toolbar:false;">$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";
}</pre>
<p>I want to send an XML file created using <code>DOMDocument</code> to an FTP server, but I cannot succeed. </p>
<p><code>ftp_put</code> returns false. </p>
This worked:
results in
ftp_put
(or any other transfer command such asftp_get
,ftp_nlist
,ftp_rawlist
,ftp_mlsd
) The most common reason for problems is that PHP defaults to active mode. In 99% of cases, switching to passive mode is required for the transmission to work properly. Useftp_pasv
function.ftp_pasv
must be called afterftp_login
. Calling it before has no effect.See also:
Additionally, if your FTP server reports the wrong IP address when responding to the
PASV
command (this is fairly common if the server is behind a firewall/NAT), you may need to do this by using solve:SeePHP FTP Passive FTP server is behind NAT.
Although in this case the correct solution is to repair the server.