如何将文件从服务器发送到另一台服务器,服务器不具有22端口

时间:2019-02-14 03:48:02

标签: php sftp

我想将服务器上的文件传输到另一台端口号为220且使用SFTP协议的服务器上。当我执行以下代码时,使用正确的用户名和密码建立了与该服务器的连接,但是文件未在目标位置传输。

我的本​​地服务器是Azure,目标是Windows服务器。请提出。

这是我尝试使用的代码:

<?php
   $localFile='/filepath/file1.txt';
   $remoteFile='/remote_server_files/file1.txt';

   $host = "hostname";
   $port = 220;//Here that server is open with 220 port
   $user = "username";
   $pass = "password";

   echo "<pre>result of connection----".$connection = ssh2_connect($host, $port);
   ssh2_auth_password($connection, $user, $pass);
   $sftp = ssh2_sftp($connection);

   $stream = fopen("ssh2.sftp://$sftp$remoteFile", 'w');
   $file = file_get_contents($localFile);
   echo "<br>result of file write----".fwrite($stream, $file);
   fclose($stream);
?>

0 个答案:

没有答案
相关问题