Search code examples
sshsftpputty

Displaying long SFTP directory listing in PuTTY


I am using PuTTY to connect to an intermediate server and sftp to connect further to a production server. Once I type in ls command on a production server a lot of files appear and I cannot see them all because there are too many files.

I've trying using ls | less, but that doesn't work:

 sftp> ls | less
 Couldn't stat remote file: No such file or directory
 Can't ls: "/export/home/wbcm/|" not found

Solution

  • Three different solutions:

    Increasing PuTTY's scrollback

    You are probably limited by PuTTY's default scrollback of 2000 lines.

    Go to the Windows page of PuTTY configuration dialog and locate the Lines of scrollback box. Enter a value larger than default 2000.

    PuTTY lines of scrollback

    Proper use of the less command

    Regarding the ls | less. You are in the sftp, not in a shell. There's no less command in the OpenSSH sftp client. Let alone an output piping (the |). You need to apply the less to an output of the sftp command. E.g.:

    echo "ls /home/username/zillions_of_files" | sftp [email protected] | less
    

    See files in WinSCP using tunneling

    I'm assuming that you ssh (using PuTTY) to some server, where you sftp (using the OpenSSH command line client) to another (production) server, because you cannot sftp directly to the production server from your Windows machine (that being the reason you cannot connect using WinSCP). If that's the case, use the tunneling feature of WinSCP to bypass the restriction and list the files directly in WinSCP.

    (I'm the author of WinSCP)