如何从Ubuntu中的Laravel应用程序访问Windows服务器中的文件?

如何从Ubuntu中的Laravel应用程序访问Windows服务器中的文件?

问题描述:

I need to connect through ssh from a Laravel application hosted in Ubuntu to a Windows server where I want to retrieve some files in order to use them within my application.

The Laravel Application is hosted in Ubuntu with nginx 1.14 and using PHP 7.3.6 and Laravel 5.8.

The files I need to use (By 'use' I mean read, edit, download and upload) in Laravel need to stay in that Windows server because moving them to Linux would be too much of a hassle for the people who create these files (Excel worksheets, text files, csv files) and for me because I would have to configure the samba shared folders on every PC here.

I have tried using ssh to connect to the Windows server and it shows the login prompt but no credentials are working (It's within a domain and I've tried with 'domain\username' but to no effect :( ).

Summary

  • Files in Windows server: xlsx, csv, txt
  • Operations: read, edit, donwload, upload.
  • Laravel application is hosted in Ubuntu.
  • Can't connect through ssh from Ubuntu to Windows server.

  • Ubuntu server configuration:

    • Ubuntu 18.04
    • Nginx 1.14.0
    • Laravel 5.8
    • PHP 7.3.6

My login attempts:

sys@server:~$ sudo ssh arebollar@xx.xx.xx.xx
arebollar@xx.xx.xx.xx's password:
Permission denied, please try again.

arebollar@xx.xx.xx.xx's password:
Permission denied, please try again.

arebollar@xx.xx.xx.xx's password:
Received disconnect from xx.xx.xx.xx port 22:2: Too many attempts.
Disconnected from xx.xx.xx.xx port 22


sys@server:~$ sudo ssh AzureAD\arebollar@xx.xx.xx.xx
AzureADarebollar@xx.xx.xx.xx's password:
Permission denied, please try again.

AzureADarebollar@xx.xx.xx.xx's password:
Permission denied, please try again.

AzureADarebollar@xx.xx.xx.xx's password:
Received disconnect from xx.xx.xx.xx port 22:2: Too many attempts.
Disconnected from xx.xx.xx.xx port 22


sys@server:~$ sudo ssh domain\arebollar@xx.xx.xx.xx
domainarebollar@xx.xx.xx.xx's password:
Permission denied, please try again.

domainarebollar@xx.xx.xx.xx's password:
Permission denied, please try again.

domainarebollar@xx.xx.xx.xx's password:
Received disconnect from xx.xx.xx.xx port 22:2: Too many attempts.
Disconnected from xx.xx.xx.xx port 22

我需要通过ssh从Ubuntu中托管的Laravel应用程序连接到我想要检索某些文件的Windows服务器 为了在我的应用程序中使用它们。 p>

Laravel应用程序托管在Ubuntu中,使用nginx 1.14并使用PHP 7.3.6和Laravel 5.8。 p>

我需要使用的文件(通过'使用',我的意思是阅读,编辑,下载和上传)需要留在Windows服务器中,因为将它们移动到Linux对于创建这些文件的人来说太麻烦了 (Excel工作表,文本文件,csv文件)对我来说因为我必须在这里配置每台PC上的samba共享文件夹。 p>

我尝试使用ssh连接到Windows服务器 它显示登录提示但没有凭据正在运行(它在一个域内,我尝试使用'domain \ username'但没有效果:()。 p>

摘要 strong> p>

  • Windows服务器中的文件:xlsx,csv,txt li>
  • 操作:读取,编辑,下载,上传。 li>
  • Laravel应用程序托管在Ubuntu中。 li>
  • 无法通过ssh从Ubuntu连接到Windows服务器 。 p> li>

  • Ubuntu服务器配置: p>

    • Ubuntu 18.04 li>
    • Nginx 1.14 .0 li>
    • Laravel 5.8 li>
    • PHP 7.3.6 li> ul> li> ul>

      我的登录尝试: p>

        sys @ server:〜$ sudo ssh arebollar@xx.xx.xx.xx 
      arebollar@xx.xx.xx.xx的密码:  
      许可被拒绝,请再试一次。
       
      arebollar@xx.xx.xx.xx的密码:
      许可被拒绝,请再试一次。
       
       
      narebollar@xx.xx.xx.xx的密码:
      已接受与xx的断开连接。  xx.xx.xx端口22:2:尝试次数过多。
      从xx.xx.xx.xx端口22 
       
       
      sys @ server断开连接:〜$ sudo ssh AzureAD \ arebollar@xx.xx.xx.xx  
      AzureADarebollar@xx.xx.xx.xx的密码:
      许可被拒绝,请再试一次。
       
      AzureADarebollar@xx.xx.xx.xx的密码:
      许可拒绝,请再试一次。
       
      AzureADarebollar@xx.xx  .xx.xx的密码:
      已从x断开连接 x.xx.xx.xx端口22:2:尝试次数过多。
      从xx.xx.xx.xx端口22 
       
       
      sys @ server断开连接:〜$ sudo ssh domain \ arebollar@xx.xx.xx  .xx 
      domainarebollar@xx.xx.xx.xx的密码:
      许可被拒绝,请再试一次。
       
      domainarebollar@xx.xx.xx.xx的密码:
      许可被拒绝,请再试一次。
       
      domainarebollar @ xx  .xx.xx.xx的密码:
      已从xx.xx.xx.xx端口22:2接收断开连接:尝试次数过多。
      从xx.xx.xx.xx端口22连接
        code>  pre>  
        div>

I'm posting this answer for anyone who is struggling with an issue like mine.

I finally solved this using ftp, accesing the files like this:

Storage::disk('ftp')->files($this->filePath.$filename)

I added a ftp local disk in config/filesystems.php:

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

...

        'ftp' => [
            'driver'   => 'ftp',
            'host'     => env('FTP_HOST'),
            'username' => env('FTP_USERNAME'),
            'password' => env('FTP_PASSWORD'),
        ],

And finally added the ftp parameters to the .env file and ran:

php artisan config:cache

Hope this helps someone else. :)