0

我正在尝试通过脚本将文件从我的网络服务器上传到我的游戏服务器。问题是它找不到目录。

完整目录为 /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); 
4

2 回答 2

0

如果那是 Linux 服务器,请确保您对目录名称使用正确的大小写。

“tf/addons/sourcemod/configs”与“TF/addons/sourcemod/configs”不同;

于 2013-08-15T19:20:40.537 回答
0

我注意到您要连接的 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. 您仍然可以对本地文件使用文件路径。

于 2013-08-15T20:12:31.330 回答