Copy Parent folder with FTP and Winscp in bat file

Asked

Viewed 549 times

3

Talk to the guys, baby?

I’m venturing to create myself a backup tool for an FTP, and I’m using Winscp to connect and use the Synchronize command for me.

set FTPSERVER=MEUHOST
set FTPUSER=USUARIO
set FTPPASS=SENHA
set LOCALE=C:\arquivos
set FTPREMOTO=\backup
"F:\Programas\WinSCP\winscp.com" /command "open ftp://%FTPUSER%:%FTPPASS%@%FTPSERVER%/" ^
  "synchronize remote ""%LOCALE%"" ""%FTPREMOTO%"" " ^      
exit

Good so far connects and makes the copy very neat.

But it just copies the files inside C:\arquivos straight to the pulp backup, and does not create the folder arquivos. I could manually create this folder and play there. But this function that I am doing will be fed later with several other folders, then having to keep creating one by one does not pay off. Is there any way, when sending to FTP, to consider the parent folder? As if it were a command cd.. and capture that briefcase? So on my host would stay backup\arquivos

1 answer

3


"F:\Programas\WinSCP\winscp.com" /command ^
  "open ftp://%FTPUSER%:%FTPPASS%@%FTPSERVER%/" ^
  "option batch continue" ^
  "mkdir backup/arquivos" ^
  "option batch abort" ^
  "synchronize remote ""C:\arquivos"" ""backup/arquivos"" " ^ 
  "exit"

Unfortunately, I do not Speak English, so I can provide only English Explanation: The point of my Answer is to create the subfolder (mkdir), but Prevent failing in case the subfolder exists already (option batch continue).

Anyone: Feel free to Edit my Answer with Translation.

  • 1

    You could bring along to your code an explanation about it?

  • 3

    @Andréfilipe I would like to, but unfortuntely, I do not Speak English. -- Anyway, the point of my Answer is to create the subfolder (mkdir), but Prevent failing in case the subfolder exists already (option batch continue).

  • 1

    It worked as needed. Now with some folders can’t make it work, but its Most likely been a problem with the Quotes escapes. But the code with batch continue worked Perfectly. (Worked as needed. Now some folders can not work, but it is likely that it is because of the quotes that need to escape correctly. But the code with batch continue worked perfectly

Browser other questions tagged

You are not signed in. Login or sign up in order to post.