Today I was setting up a dev environment. I had to transfer some file from my windows workstation to my in-house linux server. I used PuTTY’s pscp to do it, but I got an unpleasant surprise. It turns put pscp will do different things depending on whether you use a backslash(\) or not. Consider this:
pscp.exe -r Path\to\Dir\ user@remote:/path/to/destination
What do you expect that to do? I would expect it to copy Dir and it’s contents over to the destination directory on the remote machine. This is what cp would do if you do this:
cp /some/local/dir/ /other/local/dir/
But that is not what pscp does. pscp copies the contents of Dir over to destination. This might not be what you want. What you usually want is a new dir, called Dir, be created on destination on the remote machine, and then copy the contents of the local Dir to the remote newly created Dir. Instead, pscp will not create a Dir on the remote computer, but put the contents of the local Dir on destination. This could end up making a real mess.
If you want pscp to create a Dir on the remore machine and then put the contents of the local Dir on the remote Dir, you would have to leave the last backslash out:
pscp.exe -r Path\to\Dir user@remote:/path/to/destination
This problem could be seen as both, a problem, or a feature, depending on what your point of view is. I don’t know if spc on linux behaves the same, but I know that cp on linux doesn’t.
If you have problem understanding the difference, imagine this:
Contents of local Dir: file1.txt file2.txt
Dir\ file1.txt file2.txt
Contents of remote destination: file.php file2.php
destination/ file.php file2.php
pscp.exe -r Path\to\Dir\ user@remote:/path/to/destination:
destination/ file.php file2.php file1.txt file2.txt
pscp.exe -r Path\to\Dir user@remote:/path/to/destination:
destination/ file.php file2.php Dir/ file1.txt file2.txt
Ultimately, using the backslash at the end should be advised against. After all, it is easier to take the contents of the new Dir up to destination than it is looking for all the contents of Dir scattered all over destination to place them inside the new Dir.
What do you think?