通过 FTP 使用 WinSCP 上传文件的命令?

发布于 2024-10-15 08:03:24 字数 608 浏览 9 评论 0原文

我有一个 FTP 服务器,但不知道从 PHP 表单上传的命令。我需要一个用 WinSCP 上传的命令。到目前为止我的代码如下:

<html>
<body>

<?php


if(isset($_FILES["uploaded"]))
{
print_r($_FILES);
if(move_uploaded_file($_FILES["uploaded"]["tmp_name"],"<root>/domains/sigaindia.com/public_html/reymend/".$_FILES["uploaded"]["name"])) 
echo "FILE UPLOADED!";
}
else
{
 print "<form enctype='multipart/form-data' action='fup1.php' method='POST'>";
 print "File:<input name='uploaded' type='file'/><input type='submit' value='Upload'/>";
 print "</form>";
}

?>

</body>
</html>

I have an FTP server, but don't know the command to upload from a PHP form. I need a command to upload with WinSCP. My code so far is below:

<html>
<body>

<?php


if(isset($_FILES["uploaded"]))
{
print_r($_FILES);
if(move_uploaded_file($_FILES["uploaded"]["tmp_name"],"<root>/domains/sigaindia.com/public_html/reymend/".$_FILES["uploaded"]["name"])) 
echo "FILE UPLOADED!";
}
else
{
 print "<form enctype='multipart/form-data' action='fup1.php' method='POST'>";
 print "File:<input name='uploaded' type='file'/><input type='submit' value='Upload'/>";
 print "</form>";
}

?>

</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南风起 2024-10-22 08:03:24
$host = "ftp.example.com";
$user = "anonymous";
$pass = "";

// You get this from the form, so you don't need to do move_uploaded_file()
$fname = "/public_html/new_file.txt";
$fcont = "content";

function ftp_writeFile($ftp, $new_file, $content, $debug=false) {
    extract((array)pathinfo($new_file));

    if (!@ftp_chdir($ftp, $dirname)) {
        return false;
    }

    $temp = tmpfile();
    fwrite($temp, $fcont);
    rewind($temp);  

    $res = @ftp_fput($ftp, $basename, $temp, FTP_BINARY);
    if ($debug) echo "a- '$new_file'".(($res)?'':" [error]")."<br/>";
    fclose($temp);

    return $res;
}

$ftp = ftp_connect($host);
if (!$ftp) echo "Could not connect to '$host'<br/>";

if ($ftp && @ftp_login($ftp, $username, $password)) {
    ftp_writeFile($ftp, $fname, $fcont, true);
} else {
    echo "Unable to login as '$username:".str_repeat('*', strlen($password))."'<br/>";
}

ftp_close($ftp);

http://au.php.net/manual/en/book.ftp.php

$host = "ftp.example.com";
$user = "anonymous";
$pass = "";

// You get this from the form, so you don't need to do move_uploaded_file()
$fname = "/public_html/new_file.txt";
$fcont = "content";

function ftp_writeFile($ftp, $new_file, $content, $debug=false) {
    extract((array)pathinfo($new_file));

    if (!@ftp_chdir($ftp, $dirname)) {
        return false;
    }

    $temp = tmpfile();
    fwrite($temp, $fcont);
    rewind($temp);  

    $res = @ftp_fput($ftp, $basename, $temp, FTP_BINARY);
    if ($debug) echo "a- '$new_file'".(($res)?'':" [error]")."<br/>";
    fclose($temp);

    return $res;
}

$ftp = ftp_connect($host);
if (!$ftp) echo "Could not connect to '$host'<br/>";

if ($ftp && @ftp_login($ftp, $username, $password)) {
    ftp_writeFile($ftp, $fname, $fcont, true);
} else {
    echo "Unable to login as '$username:".str_repeat('*', strlen($password))."'<br/>";
}

ftp_close($ftp);

http://au.php.net/manual/en/book.ftp.php

寒江雪… 2024-10-22 08:03:24

我有一个 FTP 服务器,但不知道从 PHP 表单上传的命令。我需要一个用 WinSCP 上传的命令。到目前为止我的代码如下:

如果您谈论的是 PHP 和表单,那么那就是 HTTP - HTTP 不是 FTP,反之亦然。

WinSCP 是一个 SSH 客户端。 SSH 是与 HTTP 不同的协议。 SSH 是与 FTP 不同的协议。

如果您希望 PHP 脚本将上传到 Web 服务器的文件传输到 FTP 服务器,请尝试以下操作:

foreach ($_FILES as $f) {
    if (file_exists($f['tmp_name'])) {
       $dest = 'ftp://' . $username . ':' . $password .
               '@' . $ftpserver . $ftp_path;
       file_put_contents($f['tmp_name'], $dest);
    }
}

I have an FTP server, but don't know the command to upload from a PHP form. I need a command to upload with WinSCP. My code so far is below:

If you're talking about PHP and forms than that's HTTP - HTTP is not FTP and vice versa.

WinSCP is an SSH client. SSH is a different protocol from HTTP. SSH is a different protocol from FTP.

If you want your PHP script to transfer files uploaded to the webserver to an FTP server, try something like:

foreach ($_FILES as $f) {
    if (file_exists($f['tmp_name'])) {
       $dest = 'ftp://' . $username . ':' . $password .
               '@' . $ftpserver . $ftp_path;
       file_put_contents($f['tmp_name'], $dest);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文