when synchronize create remote directory if not exists

Advertisement

unknown
Donor
Joined:
Posts:
4

when synchronize create remote directory if not exists

When scripting, can winscp create remote directory (and its parents directories) if not exists?

e.g. when i need to backup the following folders

local "C:\Users\a\Desktop" -> remote "a\Desktop"
local "C:\Users\b\Desktop" -> remote "b\Desktop"
local "C:\Users\c\Desktop" -> remote "c\Desktop"

my script need to do the following:
mkdir a
cd a
lcd a
synchronize Desktop Desktop
cd ..

.......

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: when synchronize create remote directory if not exists

The root destination directory has to exist prior to synchronization. Any absent sub-directories will be created.

Reply with quote

unknown
Donor
Joined:
Posts:
4

Re: when synchronize create remote directory if not exists

martin wrote:

The root destination directory has to exist prior to synchronization. Any absent sub-directories will be created.

but when scripting, it is tedious and error-prone, to repeat: mkdir->cd->mkdir->cd->...->synchronize->go to parent directory->..->go to parent directory.

Besides, there is no formal documentation for cd to parent directory.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: when synchronize create remote directory if not exists

Not sure, if I understand you. As I wrote, subdirectories are created.

So if you execute: synchronize remote c:\web /home/username/httpdocs only the httpdocs needs to exist.
If there's c:\web\images, but not /home/username/httpdocs/images, the images subfolder is created.

Reply with quote

Guest

Re: when synchronize create remote directory if not exists

martin wrote:

Not sure, if I understand you. As I wrote, subdirectories are created.

So if you execute: synchronize remote c:\web /home/username/httpdocs only the httpdocs needs to exist.
If there's c:\web\images, but not /home/username/httpdocs/images, the images subfolder is created.

Sometimes there is a need to sync a few subfolders only

e.g. Desktop,Documents,Music insides user profile directory, as there is too many garbage insides

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: when synchronize create remote directory if not exists

Sometimes there is a need to sync a few subfolders only

e.g. Desktop,Documents,Music insides user profile directory, as there is too many garbage insides
How's that related?

Reply with quote

adam
Joined:
Posts:
5

Re: when synchronize create remote directory if not exists

martin wrote:

Not sure, if I understand you. As I wrote, subdirectories are created.

So if you execute: synchronize remote c:\web /home/username/httpdocs only the httpdocs needs to exist.
If there's c:\web\images, but not /home/username/httpdocs/images, the images subfolder is created.

I believe OP desires functionality same as GNU coreutil's "cp --parents"

https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html
‘--parents’
Form the name of each destination file by appending to the target directory a slash and the specified name of the source file. The last argument given to cp must be the name of an existing directory. For example, the command:
          cp --parents a/b/c existing_dir
copies the file a/b/c to existing_dir/a/b/c, creating any missing intermediate directories.

Using your example,

mkdir c:\web; cd c:\web
synchronize local -parents c:\web /home/username/httpdocs
if c:\web\home\username\httpdocs does not exist, then 
  mkdir home; mkdir home\username; mkdir home\username\httpdocs;
  get /home/username/httpdocs/* c:\web\home\username\httpdocs
else 
  synchronize c:\web\home\username\httpdocs /home/username/httpdocs

It is similar to my request of creating empty directories, https://winscp.net/forum/viewtopic.php?t=14131 only implemented at the scripting level. Essentially it allows for retaining a directory structure without having to transfer all parent sibling objects. My desire for this at the GUI level is a user can slowly recreate a remote directory structure on their local drive slowly, as needed. Which makes it easier to synchronize if they have already grabbed a few sub-folders of a target sync directory.

I can see this being a useful enhancement.
As an initial progression to get this functionality included, perhaps a workable goal would be a mkdir -parents option?

https://www.gnu.org/software/coreutils/manual/html_node/mkdir-invocation.html

Thank you for all your hard work on this program!

Reply with quote

xxyy
Guest

Re: when synchronize create remote directory if not exists

martin wrote:

Thanks for the explanation. Will consider it.

Was this ever implemented? I find myself needing the same feature.

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: when synchronize create remote directory if not exists

No it was not. Why don't you just create the directory?

Reply with quote

Guest

Re: when synchronize create remote directory if not exists

martin wrote:

No it was not. Why don't you just create the directory?

In the end that's what I had to do with PuTTYs plink.exe and `mkdir -p`, but the reason for it in my case was the remote machine is expected to be re-created at any time, making the remote directory something that could exist, or could not. So having an automated script fail because it tried to make a directory that already existed was a pain. See the following:

Error creating folder '/opt/app/web'.
General failure (server should provide error description).
Error code: 4
Error message from server: Failure
Common reasons for the Error code 4 are:
- Renaming a file to a name of already existing file.
- Creating a directory that already exists.
- Moving a remote file to a different filesystem (HDD).
- Uploading a file to a full filesystem (HDD).
- Exceeding a user disk quota.
(A)bort, (R)etry, (S)kip: Skip


I think the docs say there's a way to ignore this and continue on but I wasn't able to get it to work.

Thank you for the reply, though. You can consider my specific problem solved via workaround; but I would have liked to avoid using plink.exe for this.

Reply with quote

Advertisement

You can post new topics in this forum