1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

FYI: WinSCP may work incorrectly when using the standard Busybox 'cp'.

Discussion in 'Asuswrt-Merlin' started by Twiglets, Jun 19, 2018.

  1. Twiglets

    Twiglets Regular Contributor

    Joined:
    Aug 15, 2014
    Messages:
    122
    I have logged an issue with WinSCP Support to try to resolve an issue where WinSCP does not copy files correctly when performing a 'Duplicate' action on a RT-AC56U running Asuswrt-Merlin 384.5.
    See https://winscp.net/forum/viewtopic.php?p=84940#84940

    It looks like the issue is that the Busybox 'cp' command is not compatible with the commandline used by WinSCP.
    I have been able to solve it by installing cp from the 'coreutils. (opkg install coreutils-cp).
    This installs a 'cp' that is compatible with the commandline used by WinSCP.

    This is a 'heads Up' in case someone else has the same problem or has not noticed the problem.

    The issue is still being looked at BUT I doubt WinSCP will change just to handle a problem on a router when there is a workaround to solve it and WinSCP works everywhere else.

    Likewise, I do not expect the Busybox 'cp' will be changed just because WinSCP has a problem.
     
  2. Please support SNBForums! Just click on this link before you buy something from Amazon and we'll get a small commission on anything you buy. Thanks!
  3. kfp

    kfp Very Senior Member

    Joined:
    Jun 26, 2014
    Messages:
    641
    If you’re using Windows 10, probably more convenient to use the built-in OpenSSH client including scp.exe
     
  4. Twiglets

    Twiglets Regular Contributor

    Joined:
    Aug 15, 2014
    Messages:
    122
    Sorry, religiously object to Windows 10 :D;)
    Like to control what information I leak and to whom ...... not to mention the 'Chad Valley' UI !!! :D
     
  5. kfp

    kfp Very Senior Member

    Joined:
    Jun 26, 2014
    Messages:
    641
    Heh, maybe putty has a better implementation as well? I’ve used their pscp.exe to transfer files to/from Asus routers.
     
  6. RMerlin

    RMerlin Super Moderator

    Joined:
    Apr 14, 2012
    Messages:
    27,225
    Location:
    Canada
    I also regularly use scp to move files between my development VM and my routers, never had any issue.
     
  7. Twiglets

    Twiglets Regular Contributor

    Joined:
    Aug 15, 2014
    Messages:
    122
    I would normally agree, I have used it a lot with no issues BUT recently found this 'one example' where using 'Duplicate' (in WinSCP) copied a sub-directory over itself incorrectly !!!???

    I have been able to replicate it (multiple times) AND I have been able to solve it by using 'cp' from the coreutils package.
    [BTW: It is in the latest version (Ver5.13.2) and in a random older version I tried (Ver-5.9.5). so not a recent change or bug AFAIK.]


    The issue has raised the fact that WinSCP uses 'cp -p -r -f -T xxxxx' to copy file/directories, the Busybox 'cp' does not have the '-T flag'.
    The coreutils 'cp' does have the '-T flag' and then WinSCP works for the example where it did not !!!???

    As I stated, I do not expect WinSCP to include some exception when it works everywhere else & ditto for 'Asuswrt-Merlin' where it does work if you use the Busybox 'cp' command appropriately.

    Just a heads-up that there is an instance where the recursive copy in WinSCP does not work.


    The fact I could replicate it was the reason I raised the issue, it was not some mistype or error by me AFAIK.
    (Just tried it again, before typing this reply ...... still get the same issue !!!)
    The steps are in the issue, if someone wants to try !!!


    Basically copy a directory over another by selecting all the contents (including a subdirectory with contents) ...... note the lowest level of the subdirectory and repeat the same action.
    The subdirectory is NOT overwritten but appears within the sub-directory 1 level lower.

    In the example the contents of '.../lib/' containing a directory 'opkg...' was copied to '.../[Backup]-lib/...'
    The 1st 'Duplicate' (copy) works correctly as nothing is being overwritten.
    The 2nd 'Duplicate' (copy) writes the 'opkg' directory inside the existing 'opkg' directory instead of overwriting 'opkg' and its contents.
     
  8. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    5,715
    Location:
    UK
    @Twiglets Well, it took me quite a while to understand the problem :rolleyes:, and even longer to setup a test scenario :p.

    But yes, I can confirm your observations using the very latest WinSCP. I must admit I wasn't even aware of the Duplicate function. Not being able to browse to the destination directory feels a bit clunky though.

    As you say, the problem is specifically when copying directories that already exist in the root of the destination location.

    However there does appear to be a way around it :). If you tick the "Duplicate via local temporary copy" box the problem doesn't occur.

    Untitled.png
     
    Twiglets and kfp like this.
  9. Twiglets

    Twiglets Regular Contributor

    Joined:
    Aug 15, 2014
    Messages:
    122
    Many Thanks :D, nice to know it was not just me ..... did have some small niggling doubt BUT could not see where I was going wrong.
    It is very specific to the 'Duplicate' action and only if you overwrite a Directory.

    Never thought of the 'via Temporary copy' work around :(:rolleyes:
    (I have never used the 'Temporary copy option' before !!!??? ...... until now. :D)

    I will update the issue at WinSCP.

    Solved by 2 methods ..... whichever suits best. Yay!!!! :D
     
  10. RMerlin

    RMerlin Super Moderator

    Joined:
    Apr 14, 2012
    Messages:
    27,225
    Location:
    Canada
    Busybox does not support the -T flag (at least the option isn't available in 1.25, I didn't check later releases). Since so many embedded devices run busybox, might be worth raising the issue to WinSCP developers.
     
    sfx2000 and Twiglets like this.
  11. Twiglets

    Twiglets Regular Contributor

    Joined:
    Aug 15, 2014
    Messages:
    122
    I have updated the issue with both solutions and advised that the '-T Flag' is missing on Busybox implementations and may require some documentation to cover the possible issues.

    Thanks all for your Help, confirming the error and solving the problem in an easier way.
     
    kfp likes this.
  12. sfx2000

    sfx2000 Part of the Furniture

    Joined:
    Aug 11, 2011
    Messages:
    12,676
    Location:
    San Diego, CA
    cp -T (no target directory) is part of GNU's coreutils package, but the -T flag itself is outside of posix....

    http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cp.html#tag_20_24

    GNU's cp...

    http://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html#cp-invocation

    Not a bug in busybox - it's a flawed assumption by the authors of WinSCP - not every host will be running a cp that supports that command (and not every host that supports scp is gnu-linux - BSD native cp doesn't support that flag either)
     
    ColinTaylor and Twiglets like this.
  13. sfx2000

    sfx2000 Part of the Furniture

    Joined:
    Aug 11, 2011
    Messages:
    12,676
    Location:
    San Diego, CA
    Sounds like a decent work-around...
     
  14. Twiglets

    Twiglets Regular Contributor

    Joined:
    Aug 15, 2014
    Messages:
    122
    Thanks, have passed on that it is also missing in BSD native 'cp' as well.
    To be honest I cannot remember ever using a '-T flag' and did not understand what it was meant to do, even after reading the Manpage !!!
     
  15. sfx2000

    sfx2000 Part of the Furniture

    Joined:
    Aug 11, 2011
    Messages:
    12,676
    Location:
    San Diego, CA
    Cool - just point them at the opengroup posix link...
     
  16. Twiglets

    Twiglets Regular Contributor

    Joined:
    Aug 15, 2014
    Messages:
    122
    sfx2000 likes this.
Please support SNBForums! Just click on this link before you buy something from Amazon and we'll get a small commission on anything you buy. Thanks!