1

我有这个代码:

<?php

$host = "ftp.myserver.com";
$port = 21;
$username = "my_username";
$password = "my_password";
$destination = "/folder/folder2/test.txt";
$file = __DIR__."/folder/folder2/test.txt";

$connection = ftp_connect($host, $port);
if (!$connection) 
    throw new Exception("Cannot found host");

$login = ftp_login($connection, $username, $password);
if (!$login)
    throw new Exception("Cannot login with provided credentials");

// return mime type ala mimetype extension
$finfo = finfo_open(FILEINFO_MIME);

//check to see if the mime-type starts with 'text'
$isText = substr(finfo_file($finfo, $file), 0, 4) == 'text';
$mode = $isText == true ? FTP_ASCII : FTP_BINARY;

ftp_pasv($connection, true);

$upload = ftp_put($connection, $destination, $file, $mode);
if (!$upload) {
    echo error_get_last();
}

ftp_close($connection);

当我通过 CMD 运行时,结果如下:

C:\xampp\htdocs\ftptest>php test.php

Warning: ftp_put(): Can't open that file: No such file or directory in C:\xampp\
htdocs\ftptest\test.php on line 27
Array

第 27 行在ftp_put命令中。文件夹folderfolder2在 ftp 服务器上不存在。我希望它由ftp_put(或者我应该手动检查并创建它?)

4

0 回答 0