Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#10604 closed defect (bug) (fixed)

class-wp-filesystem-ssh2.php put_contents fails

Reported by: lostinlafayette Owned by: dd32
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.8
Component: Filesystem API Keywords: has-patch commit
Focuses: Cc:


On certain systems class-wp-filesystem-ssh2->put_contents will fail if the contents of the file are empty.

One possible solution is to check the length of $content and if it is 0 append a space.

This issue prevents many people from upgrading wordpress automatically using ssh.

Could not copy file: /home/complete_blog/public_html/blog/wp-content/upgrade/wordpress-2.8.47/wordpress/wp-includes/js/codepress/engines/khtml.js

Attachments (1)

10604.diff (591 bytes) - added by dd32 6 years ago.
props lostinlafayette

Download all attachments as: .zip

Change History (8)

#1 @lostinlafayette
6 years ago

On second thought the issue is more likely due to file.php not using the correct comparison on the return value of $fs->put_contents. It should be $fs_put_contents(...)==false instead of !$fs_put_contents(...) which when given an empty file will incorrectly fail even though the file was successfully written.

#2 @lostinlafayette
6 years ago

I missed an equal sign, should be ===

#3 @ShaneF
6 years ago

Umm... I been getting this exact error. I'll look into it as well.

#4 @dd32
6 years ago

  • Keywords has-patch needs-testing added
  • Milestone changed from Unassigned to 2.9
  • Version set to 2.8

-finally-.. :)

Learn something new every day, I didnt realise file_put_contents returns the number of bytes written..

WP_Filesystem_SSH2::put_contents() needs to change from:

function put_contents($file, $contents, $type = '' ) {
		$file = ltrim($file, '/');
		return file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);


function put_contents($file, $contents, $type = '' ) {
		$file = ltrim($file, '/');
		return false !== file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);

So that it returns a boolean result.. False (ie failure) will still come through, but all integer or true values will come through as true.

see patch.

6 years ago

props lostinlafayette

#5 @lostinlafayette
6 years ago

The patch works great. I hope to see this included soon.

#6 @dd32
6 years ago

  • Keywords commit added; needs-testing removed

#7 @azaozz
6 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [11818]) Fix class-wp-filesystem-ssh2 put_contents() for empty files, props lostinlafayette dd32, fixes #10604

Note: See TracTickets for help on using tickets.