Reputation: 750
I'm trying to transfer files to a shared hosting account (godaddy) and it's failing:
Warning: ssh2_scp_send(): Failure creating remote file: failed to send file in 'local/file/path'
I have SSH2 installed and the connection is working. I even ran a ssh2_exec command to see if I can affect the remote server and I was able to create a directory. I also successfully used scp directly on the command line going both ways... As a further troubleshooting attempt, I reversed the file paths and created a remote server file for it to attempt downloading, I get this error:
failed to open stream: No such file or directory
I called the host to make sure I'm using the correct absolute file path, I've tried many variations, and I still get this error. I think my issue lies somewhere with the remote file path.
The problem code is below:
$localpath=$_SERVER['DOCUMENT_ROOT'].'/local_file_path/' ;
$remotepath = 'website.com/public_html/folder/' ;
$connection = ssh2_connect('website.com', 22);
ssh2_auth_password($connection,'username','password' );
ssh2_scp_send($connection,"$localpath"."SUCCESS.txt", "$remotepath"."SUCCESS.txt", 0644);
I am also having issues trying to use sftp via PHP. I read elsewhere on the web that you have to use double quotes on the file paths, whenever they fail, the printed path appears correct, but perhaps I'm missing something?
UPDATE
I logged into the shared hosting account via sftp with filezilla and discovered that, when copied, the full url path is different then what I was being given when logged in threw regular ftp. I can now upload a file, but, I can't seem to download just yet, ironically... I still get the error about not being able to locate the file path on the remote server.
Upvotes: 3
Views: 16518
Reputation: 151
ssh2_scp_send need absolute path, I solved my issue by using pwd
where I need to send my files. ~/
dont works either, it's not an absolute path.
The bottom comment on this page http://www.php.net/manual/en/function.ssh2-scp-send.php refers to a problem you might be having.
I suggest that, use phpseclib or ssh2_sftp
Interesting topics:
Upvotes: 5