PHP Uploading files using SFTP

Source: Internet
Author: User
Tags connection reset

Make this SFTP file transfer all day really drunk, from SFTP installation, to PHP ssh2 extension installation, and finally to the PHP application ssh2 to upload files; Finally, there's no end.

Failure Creating remote file: (NULL) This error has been reported! Online can search the basic find a time does not work, at first thought laravel frame problem, later written as a native PHP script is also this error, fine! Very good really do not have;

Workaround:

Use league/flysystem-sftp This while the plug-in to run SFTP file transfer, in the composer download relies on the use of the method is also very simple

UseLeague\flysystem\sftp\sftpadapter;UseLeague\flysystem\filesystem;$adapter=NewSftpadapter ([ ' Host‘=' example.com‘, ' Port‘=02n ' Username‘=' Username‘, ' Password‘=' Password‘, ' Privatekey‘= ' Path/to/or/contents/of/privatekey   ' Root ' = >  '/path/to/root "  "Timeout => 10 ,   ' Directoryperm '  = = 0755);  $filesystem =  New filesystem ( $adapter);         
//After getting to object
1. $filesystem->put (' Remote file path ', ' content ');
2. $filesystem->putstream (' Remote file path ', ' file handle ');//Get Handle by fopen


Personal Memo:
SSH is installed in the Linux/ubuntu system with SFTP, and if it is not configured, it will not connect to the remote
Unable to negotiate with 113.105.66.197 Port 8521:no matching host key type found. Their OFFER:SSH-DSS
Couldn ' t read packet:connection reset by peer
Workaround:
Add config file under/personal directory/.ssh/
VI/Personal directory/.ssh/config
Hostkeyalgorithms +ssh-dss Add this phrase save exit and try to connect the SFTP

PHP Uploading files using SFTP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.