我试图通过FTP连接从一个服务器发送一个文件到另一个服务器。我能够创建连接并将文件发送到我想要的文件夹。
文件是创建的,但它有0字节。此外,php函数在使用此错误消息一段时间后就会失败:
连接超时
我还更改了接收文件的服务器上文件夹的权限,它具有公共read、write和execute权限,但是,当新文件到达服务器时,它没有默认权限,而只有read权限。
我可能做错了什么?
这是我的密码:
$localFile = $_SERVER['DOCUMENT_ROOT'].'/images/'.$file;
$moveFile = '/public_html/images/'.$file;
$ftp_server = 'ftp.mywebsite.com';
$ftp_username = 'xxxxxx';
$ftp_password = 'xxxxxx';
$ftp_connection = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$ftp_login = ftp_login($ftp_connection, $ftp_username, $ftp_password);
if ( ftp_put($ftp_connection, $moveFile, $localFile, FTP_ASCII) ) {
print_r('Completed');
} else {
print_r('Error');
}发布于 2017-02-20 18:12:00
我遇到了同样的问题,在ftp登录后设置ftp_pasv($conn_id, true);就解决了-我的代码如下所示-
$ssl_connection_id = ftp_ssl_connect(FTP_HOST);
if($ssl_connection_id)
{
$login = ftp_login($ssl_connection_id,FTP_USERNAME, FTP_PASSWORD);
ftp_pasv($ssl_connection_id, true);
if($login)
{
if (ftp_put($ssl_connection_id,FTP_PATH.$filename, $localFile, FTP_ASCII))
{
echo "successfully uploaded \n";
}
}
}仅此而已,另一个不同之处是,我使用IP地址而不是url(ftp.mywebsite.com),比如5.xx.xx.xxx。
https://stackoverflow.com/questions/42351065
复制相似问题