[英]File won't upload to ftp server
我正在尝试通过脚本将文件从网络服务器上传到游戏服务器。 问题在于它找不到目录。
完整目录为/174.34.132.106端口27015 / tf / addons / sourcemod / configs / tf2items.weapons.txt
该路径不起作用,所以我向主机询问了有关信息,他们坚持认为/tf/addons/sourcemod/configs/tf2items.weapons.txt是正确的路径,但这也不起作用。 游戏服务器在Windows服务器上运行,我很确定Web服务器在Linux上运行。 我的代码是否错误,是否必须用%20替换目录中的空格。 提前致谢!
$ftp_server="174.34.132.106";
$ftp_user_name="Username";
$ftp_user_pass="Password";
$remote_file = "tf2items.weapons.txt";
$file = "weapons/tf2items.weapons.txt";//tobe uploaded
if(!file_exists($file)) echo "The local file does not exist";
$conn_id = ftp_connect($ftp_server) or die('Unable to create the connection');
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_chdir($conn_id, "174.34.132.106 port 27015/tf/addons/sourcemod/configs/");
echo ftp_pwd($conn_id);
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
exit;
} else {
echo "There was a problem while uploading $file\n";
exit;
}
// close the connection
ftp_close($conn_id);
如果是Linux服务器,请确保对目录名使用正确的大小写。
“ tf / addons / sourcemod / configs”与“ TF / addons / sourcemod / configs”不同;
我注意到您要连接的FTP服务器使用的是非标准端口,因此它可能未建立连接。 您需要在ftp_connect中指定端口,如下所示:
$ftp_server="174.34.132.106";
$ftp_port = "27015";
$ftp_user_name="username";
$ftp_user_pass="password";
$remote_file = "tf/addons/sourcemod/configs/tf2items.weapons.txt";
$file = "weapons/tf2items.weapons.txt";//tobe uploaded
// set up basic connection
$conn_id = ftp_connect($ftp_server,$ftp_port) or die('Unable to create the connection');
如果无法建立连接,die()将停止脚本。 您可以在ftp_login行之后添加相同的名称,以确保它实际上已登录。
编辑为了确保您的文件存在,请在ftp_put行上方尝试此操作。
if(!file_exists($file)) echo "The local file does not exist";
编辑2读完ftp_put后 ,它说remote_file不支持目录。 您首先需要使用ftp_chdir 。
ftp_chdir($conn_id, "tf/addons/sourcemod/configs/");
然后对于remote_file,仅使用tf2items.weapons.txt
。 您仍然可以使用本地文件的文件路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.