Topic "Check if remote file exists"

Author Message



perhaps somebody can help me with my problem. The main problem is that i want to move some remote files from one directory to another. If the files are already in the target directory i want to overwrite them. This task is part of a script and the number of the files to move can be different.

It is possible that some files in the target directory should stay there and other files should be replaced. For example i want to move/replace the files 'file1.txt' and 'file2.txt' and the existing file 'file3.txt' should be unchanged. With the mv-command i get an error because the files are already there.

Then i added a delete-step before i moved the files, but then i got an error, if the file, which i want to delete, does not exist.

Now i think the only way is to check for each moving-file, if the file exists in the target directory. If it exists i have to delete it and after this i can move the source file. But to check, if the file exists seems to be a new problem.

This normally simple task seems to be a problem for me. Perhaps can't see the simple solution and somebody can give me a hint.

Thanks for help
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24759
Location: Prague, Czechia
You can set "option batch continue" before the "rm" command to avoid the script be interrupted on error.
Martin Prikryl

You can post new topics in this forum

Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License