FTP to FTP / Backup and Upload between FTP (Batch Script)

Advertisement

Suisso
Guest

FTP to FTP / Backup and Upload between FTP (Batch Script)

Hello,
I need script to download all folders from an FTP and upload this same folders to another remote FTP. Unfortunately, I know the WinSCP don't support FXP (FTP to FTP directly).
I need a full script to download from FTP and upload to another remote FTP.

My script to download :
open ftp://user:pass@host/
get *.* C:\temp\1\backup\
exit
My script to upload:
open ftp://user:pass@host/
lcd C:\temp\1\backup\
put *.*
exit
And my commands to run in PowerShell is:
.\WinSCP.com /script=C:\script1.txt /log=C:\temp\log1.txt
.\WinSCP.com /script=C:\script2.txt /log=C:\temp\log2.txt
Currently I made two scripts like this and it works, but I wanted to simplify and if possible put everything in a single script and if possible to delete the source files after all the transfer 100% how to do, what is the best method?

Thanks in advance,
Best Regards

Reply with quote

Advertisement

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

Re: FTP to FTP / Backup and Upload between FTP (Batch Script)

Just concatenate the two scripts to one, removing the first exit. You can also optionally close the first connection right after the download using close command. The second lcd could be removed as it is redundant.
To delete the temporary files, you can use -delete switch of the put command.
https://winscp.net/eng/docs/scriptcommand_put#delete
open ftp://user:pass@host/
get *.* C:\temp\1\backup\
close
open ftp://user:pass@host/
put -delete *.*
exit

Reply with quote

Suisso
Joined:
Posts:
1

Re: FTP to FTP / Backup and Upload between FTP (Batch Script)

Hello Martin,
Thanks for your reply.

My final script:
open ftp://user:pass@host/
get *.* C:\temp\1\backup\
close
open ftp://user:pass@host/
lcd C:\temp\1\backup\
put -delete *.*
exit
It's worked!
If you don't put lcd it doesn't work.

I still have 2 questions:

1) I want to automate this script on Windows (taskschd.msc).
How should I put the arguments in action to launch the script? And should we put winscp.com or winscp.exe?

2) How to force to write over the directories even if they already exist, this is because this script will be launched once a day from Monday to Friday and if the same directories exist I want it replaced.

I will put a directory in remote backup ftp from 1 to 5:
1 = monday
2 = tuesday
3 = wednesday
4 = thursday
5 = friday


Is there any other more effective or simpler method of running this script once a day for the entire week?

Thanks in advance,
Best regards

hsg-1-13-15-01[1].png

Reply with quote

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

Re: FTP to FTP / Backup and Upload between FTP (Batch Script)

1) See https://winscp.net/eng/docs/guide_schedule

2) WinSCP cannot generate folder names based on order of a week days. You would have to get the number outside of WinSCP and pass it to it. E.g. using an environment variable. Ultimately that means that you will be scheduling a batch file (or other script), not WinSCP directly. So part of 1) won't apply anymore.
See https://stackoverflow.com/q/11364147/850848
https://winscp.net/eng/docs/scripting#variables

Easier would be to use date (yyyy-mm-dd or similar) or a week day name (ddd) in the folder name, as that's what WinSCP can do.
https://winscp.net/eng/docs/scripting#timestamp

Reply with quote

Advertisement

You can post new topics in this forum