problems creating link using sftp to redhat linux 6.5
Creating a link fails. The command seems to have the two file names backwards. If original file is "foo" and I want a link called "whatever" it creates a link in the home directory called "foo" (and not "whatever"). If the file I am trying to create a link to is in the home directory it will fail because the file original name is in use. I am using sftp to linux redhat 6.5. I cannot use scp protocal because that relies on /bin/ln which we currently do not have on this server.
Steps to reproduce:
First, on a linux server, sftp to a destination linux server:
$ sftp server
Connected to server.
sftp>
In a separate window, ssh to that destination server, set up the test environment, and trace the sftp command:
$ ssh server
...
$ mkdir linktest
$ cd linktest
$ touch foo
$ strace -e trace=symlink -p `pgrep -f sftp`
Process #### attached - interrupt to quit
In the first window, on the sftp command line, enter the following commands:
sftp> cd linktest
sftp> ln -s foo bar
sftp> ln -s foo baz
sftp> ln -s bar baz
Couldn't symlink file "/home/dir/linktest/bar" to "/home/dir/linktest/baz": Failure
sftp> exit
The second window reports:
symlink("/home/dir/linktest/foo", "/home/dir/linktest/bar") = 0
symlink("/home/dir/linktest/foo", "/home/dir/linktest/baz") = 0
symlink("/home/dir/linktest/bar", "/home/dir/linktest/baz") = -1 EEXIST (File exists)
Process #### detached
This shows the output for proper ordering of arguments (item being linked to first, name of new link second) and the error when you try to create a link against a name that already exists.
Now open up a winscp "sftp" connection to the same server.
Once established, start the same strace on the server.
$ strace -e trace=symlink -p `pgrep -f sftp`
Process #### attached - interrupt to quit
Select the "foo" file and try to create a symlink called "whatever" and you will see:
Dialog box. First field is empty, it is labeled "Link/shortcut file:"
Put "whatever" into this field.
Second field has the file name that you select and is labeled "Point link/shortcut to:"
The strace will generate:
symlink("/home/dir/linktest/whatever", "foo") = 0
If you do ls -l /home/dir/linktest you will NOT see the link.
If you do ls -l on /home/dir/ you see:
foo -> /home/dir/linktest/whatever
This is because the link is created in the home directory and not in the same directory as the original file (/home/dir/linktest).
HOWEVER, /home/dir/linktest/whatever does not exist.
This is because the name of the link (in dialog box in "Link/shortcut file:" field) is swapped with the file listed in "Point link/shortcut to:"
In the second window, (ssh to that destination server) create foohome in the home director.
In the winscp "sftp" connection, select foohome and create link called whateverhome.
You will see:
General failure (server should provide error description).
Error code: 4
Error messages from server: Failure
The strace will generate:
symlink("/home/dir/whateverhome", "foohome") = -1 EEXIST (File exists)
This is because the file indicated in the "Point link/shortcut to:" field is in the home directory and WinSCP is trying to create the link with the same name as the original file (in name in the "Point link/shortcut to:" field).
If you indicate the full path in the "Link/shortcut file:" field (/home/dir/linktest/whatever), it does not affect where WinSCP attempts to put the link. strace will still generate:
symlink("/home/dir/whateverhome", "foohome") = -1 EEXIST (File exists)
Steps to reproduce:
First, on a linux server, sftp to a destination linux server:
$ sftp server
Connected to server.
sftp>
In a separate window, ssh to that destination server, set up the test environment, and trace the sftp command:
$ ssh server
...
$ mkdir linktest
$ cd linktest
$ touch foo
$ strace -e trace=symlink -p `pgrep -f sftp`
Process #### attached - interrupt to quit
In the first window, on the sftp command line, enter the following commands:
sftp> cd linktest
sftp> ln -s foo bar
sftp> ln -s foo baz
sftp> ln -s bar baz
Couldn't symlink file "/home/dir/linktest/bar" to "/home/dir/linktest/baz": Failure
sftp> exit
The second window reports:
symlink("/home/dir/linktest/foo", "/home/dir/linktest/bar") = 0
symlink("/home/dir/linktest/foo", "/home/dir/linktest/baz") = 0
symlink("/home/dir/linktest/bar", "/home/dir/linktest/baz") = -1 EEXIST (File exists)
Process #### detached
This shows the output for proper ordering of arguments (item being linked to first, name of new link second) and the error when you try to create a link against a name that already exists.
Now open up a winscp "sftp" connection to the same server.
Once established, start the same strace on the server.
$ strace -e trace=symlink -p `pgrep -f sftp`
Process #### attached - interrupt to quit
Select the "foo" file and try to create a symlink called "whatever" and you will see:
Dialog box. First field is empty, it is labeled "Link/shortcut file:"
Put "whatever" into this field.
Second field has the file name that you select and is labeled "Point link/shortcut to:"
The strace will generate:
symlink("/home/dir/linktest/whatever", "foo") = 0
If you do ls -l /home/dir/linktest you will NOT see the link.
If you do ls -l on /home/dir/ you see:
foo -> /home/dir/linktest/whatever
This is because the link is created in the home directory and not in the same directory as the original file (/home/dir/linktest).
HOWEVER, /home/dir/linktest/whatever does not exist.
This is because the name of the link (in dialog box in "Link/shortcut file:" field) is swapped with the file listed in "Point link/shortcut to:"
In the second window, (ssh to that destination server) create foohome in the home director.
In the winscp "sftp" connection, select foohome and create link called whateverhome.
You will see:
General failure (server should provide error description).
Error code: 4
Error messages from server: Failure
The strace will generate:
symlink("/home/dir/whateverhome", "foohome") = -1 EEXIST (File exists)
This is because the file indicated in the "Point link/shortcut to:" field is in the home directory and WinSCP is trying to create the link with the same name as the original file (in name in the "Point link/shortcut to:" field).
If you indicate the full path in the "Link/shortcut file:" field (/home/dir/linktest/whatever), it does not affect where WinSCP attempts to put the link. strace will still generate:
symlink("/home/dir/whateverhome", "foohome") = -1 EEXIST (File exists)