What cause the error “Couldn't canonicalise: N

2020-08-09 08:13发布

问题:

I am trying to use SFTP to upload the entire directory to remote host but I got a error.(I know SCP does work, but I really want to figure out the problem of SFTP.)

I used the command as below: (echo "put -r LargeFile/"; echo quit)|sftp -vb - username@remotehost:TEST/

But I got the error "Couldn't canonicalise: No such file or directory""Unable to canonicalise path "/home/s1238262/TEST/LargeFile"

I thought it was caused by access rights. So, I opened a SFTP connection to the remote host in interactive mode and tried to create a new directory "LargeFile" in TEST/. And I succeeded. Then, I used the same command as above to uploading the entire directory "LargeFile". I also succeeded. The subdirectories in LargeFile were create or copied automatically.

So, I am confused. It seems only the LargeFile/ directory cannot be created in non-interactive mode. What's wrong with it or my command?

回答1:

With SFTP you can only copy if the directory exists. So

> mkdir LargeFile
> put -r path_to_large_file/LargeFile

Same as the advice in the link from @Vidhuran but this should save you some reading.



回答2:

This error could possibly occur because of the -r option. Refer https://unix.stackexchange.com/questions/7004/uploading-directories-with-sftp



回答3:

The easiest way for me was to zip my folder on local LargeFile.zip and simply put LargeFile.zip

zip -r LargeFile.zip LargeFile
sftp www.mywebserver.com (or ip of the webserver)
put LargeFile.zip (it will be on your remote server local directory)
unzip Largefile.zip


回答4:

A better way is through using scp.

scp -r LargeFile/"; echo quit)|sftp -vb - username@remotehost:TEST/


回答5:

If you are using Ubuntu 14.04, the sftp has a bug. If you have the '/' added to the file name, you will get the Couldn't canonicalize: Failure error.

For example:

sftp> cd my_inbox/ ##will give you an error

sftp> cd my_inbox ##will NOT give you the error

Notice how the forward-slash is missing in the correct request. The forward slash appears when you use the TAB key to auto-populate the names in the path.



标签: sftp