Uploading directories with sftp?

  • I'm having some trouble uploading directories(which contain other directories a few levels deep) by sftp. I realize I could work around this by gzipping, but I don't see why that's necessary.

    Anyway, I try

    sftp> put bin/
    Uploading bin/ to /home/earlz/blah/bin
    bin/ is not a regular file
    sftp> put -r bin/
    Uploading bin/ to /home/earlz/blah/bin
    Couldn't canonicalise: No such file or directory
    Unable to canonicalise path "/home/earlz/blah/bin"
    

    I think the last error message is completely stupid. So the directory doesn't exist? Why not create the directory?

    Is there anyway around this issue with sftp, or should I just use scp?

  • Jander

    Jander Correct answer

    10 years ago

    CORRECTED: I initially claimed wrongly that OpenSSH did not support put -r. It does, but it does it in a very strange way. It seems to expect the destination directory to already exist, with the same name as the source directory.

    sftp> put -r source
     Uploading source/ to /home/myself/source
     Couldn't canonicalize: No such file or directory
     etc.
    sftp> mkdir source
    sftp> put -r source
     Uploading source/ to /home/myself/source
     Entering source/
     source/file1
     source/file2
    

    What's especially strange is that this even applies if you give a different name for the destination:

    sftp> put -r source dest
     Uploading source/ to /home/myself/dest
     Couldn't canonicalize: ...
    sftp> mkdir dest
    sftp> put -r source dest
     Uploading source/ to /home/myself/dest/source
     Couldn't canonicalize: ...
    sftp> mkdir dest/source
    sftp> put -r source dest
     Uploading source/ to /home/myself/dest/source
     Entering source/
     source/file1
     source/file2
    

    For a better-implemented recursive put, you could use the PuTTY psftp command line tool instead. It's in the putty-tools package under Debian (and most likely Ubuntu).

    Alternately, Filezilla will do what you want, if you want to use a GUI.

    FYI: `sftp` allows `put -r` from OpenSSH 5.4

    Thanks -- I've corrected my answer. It's about time, huh? ;-P

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM