Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put requests truncate at 24402 bytes #1461

Open
ghost opened this issue Mar 12, 2020 · 4 comments
Open

Put requests truncate at 24402 bytes #1461

ghost opened this issue Mar 12, 2020 · 4 comments

Comments

@ghost
Copy link

ghost commented Mar 12, 2020

I'm having issues uploading files to an SFTP server

When making a put request, only 24402 bytes of the file make it to the SFTP server

The put line is:

$sftp->put('testfile.txt', 'testfile.txt', SFTP::SOURCE_LOCAL_FILE);

After 10 seconds or so (with the default timeout), I get this output:

PHP Notice:  Expected SSH_FXP_STATUS in /vendor/phpseclib/phpseclib/phpseclib/Net/SFTP.php on line 2089
PHP Notice:  Expected SSH_FXP_STATUS in /vendor/phpseclib/phpseclib/phpseclib/Net/SFTP.php on line 2123

If I use ->setTimeout(60), it hangs for longer but eventually puts out the same output, with the same 24402 bytes on the remote end

I'm running phpseclib 2.0 with php 5.6 on Red Hat 6, the SFTP server is Windows

I've also used ->getLog() in case that's useful. Here's the output: https://pastebin.com/9E2Kwx7S

@terrafrost
Copy link
Member

I wonder what'd happen if you did define('NET_SFTP_QUEUE_SIZE', 1); at the top of the file.

If that doesn't help then seeing the SFTP logs could help. You can get them by doing define('NET_SFTP_LOGGING', 2); at the top and then echo $sftp->getSFTPLogs(); at the bottom.

I also wonder how well that SFTP server runs with WinSCP as the client or psftp.

Is https://github.com/PowerShell/Win32-OpenSSH/releases/tag/v8.0.0.0p1-Beta what you're using? I could install, try to reproduce and create a ticket in their github tracker if appropriate (wouldn't be the first time for me)

Thanks!

@freshleafmedia
Copy link

define('NET_SFTP_QUEUE_SIZE', 1); seems to fix the issue for me.

Why is this constant doing exactly? If I had to guess from my limited knowledge of the code, the library batches its put operations and reads the result after reaching the queue size?

Should I be happy with setting this constant, or would there be a better solution?

I'm not sure what the SFTP Server is, as I've not set it up.

@terrafrost
Copy link
Member

Why is this constant doing exactly? If I had to guess from my limited knowledge of the code, the library batches its put operations and reads the result after reaching the queue size?

Yup - that's pretty much it. PuTTY's psftp and probably WinSCP, as well, do the same thing. It greatly speeds up file transfer. My guess is that if it doesn't work with phpseclib it doesn't work with either of those SFTP clients either.

FWIW I've installed https://github.com/PowerShell/Win32-OpenSSH/releases/tag/v8.0.0.0p1-Beta and am trying to see if I can reproduce the issue locally.

This wouldn't be the first bug in that package that phpseclib was the first to find: PowerShell/Win32-OpenSSH#48

Anyway, I'll let you know!

@terrafrost
Copy link
Member

I'm totally not able to reproduce the issue. I tried https://github.com/PowerShell/Win32-OpenSSH/releases/tag/v8.0.0.0p1-Beta and it identifies itself the same way as the server you connected to did, as shown in the log files you posted. Despite that the file loads without issue...

Are you able to reproduce the issue with WinSCP?

I really hate to do this but I think, for the time being, it's probably best if I dismiss this as a one-off. You have a workaround and idk that I'm prepared to undo a useful feature because of one post. At least not for the time being.

If I get more reports of this with SSH-2.0-OpenSSH_for_Windows_8.0 then I could make it so that SFTP instances to servers identifying themselves thusly auto-set define('NET_SFTP_QUEUE_SIZE', 1); just for that server. Such server software specific tweaks are not without precedent. See, for example, https://github.com/phpseclib/phpseclib/blob/1.0.18/phpseclib/Net/SSH2.php#L1363 . So phpseclib could just do something like that for SSH-2.0-OpenSSH_for_Windows_8.0 but, like I said, I'll hold off, for the time being, especially given my own inability to reproduce the issue. If I get further reports of this happening I'll look into it.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants