Automate downloads from the FTPS (Error changing directory)
Dear all,
As a first thing I would like to say big thank you to all who supports and develops WinSCP.
After a long time when I tried to find utility that I could use to download files from FTPS-server I choose WinSCP.
I checked the FAQ and a couple of threads on the forum, but unfortunately has not find the answer on my question.
What I have:
1) FTPS server with a known list of folders like (another names of folders cannot appear there):
/FTPS/folder1
/FTPS/folder2
/FTPS/folder3
/FTPS/folder4
2) About the server. I have no access to it and just can show how it works and what it going every day, but this cannot be changed.
Each day there are new files copied to these folders. But in case there are no new files for specific folder it became removed.
So for one it could appears like:
/FTPS/folder2
/FTPS/folder4
For another day:
/FTPS/folder1
/FTPS/folder2
/FTPS/folder3
/FTPS/folder4
What I need to do:
Download files on daily basis and copy them so separate network shared-drives.
How I’m doing this.
I see 2 ways here.
1st way:
Run the ftprun.bat file:
echo __________________________ %date% %time% ______________________________ >>log.txt
C:\ FTPS\winscp.com /script=C:\ FTPS\ftpscript.txt >>log.txt
echo.>>log.txt
ftpscript.txt:
option batch continue
option confirm off
open ftps://test\login:password@ip:port -explicit -certificate="certificate id"
lcd \\localserver\folder1$
/FTPS/folder1
synchronize local
lcd \\localserver\folder2$
/FTPS/folder2
synchronize local
lcd \\localserver\folder3$
/FTPS/folder3
synchronize local
lcd \\localserver\folder4$
/FTPS/folder4
synchronize local
exit
It works fine actually in case all 4 folders are available on the FTPS server, but in case one of them is missing, for example folder2, it experience error-message “Error changing directory to folder2” and is going synchronize /FTPS/folder1 with \\localserver\folder2$ that is incorrect. :evil:
2nd way:
Run the ftprun.bat file:
echo __________________________ %date% %time% ______________________________ >>log.txt
C:\ FTPS\winscp.com /script=C:\ FTPS\ftpscript_folder1.txt >>log.txt
C:\ FTPS\winscp.com /script=C:\ FTPS\ftpscript_folder2.txt >>log.txt
C:\ FTPS\winscp.com /script=C:\ FTPS\ftpscript_folder3.txt >>log.txt
C:\ FTPS\winscp.com /script=C:\ FTPS\ftpscript_folder4.txt >>log.txt
echo.>>log.txt
ftpscript_folder1.txt:
option batch continue
option confirm off
open ftps://test\login:password@ip:port -explicit -certificate="certificate id"
lcd \\localserver\folder1$
/FTPS/folder1
synchronize local
exit
ftpscript_folder2.txt:
option batch continue
option confirm off
open ftps://test\login:password@ip:port -explicit -certificate="certificate id"
lcd \\localserver\folder2$
/FTPS/folder2
synchronize local
exit
ftpscript_folder3.txt:
option batch continue
option confirm off
open ftps://test\login:password@ip:port -explicit -certificate="certificate id"
lcd \\localserver\folder3$
/FTPS/folder3
synchronize local
exit
ftpscript_folder4.txt:
option batch continue
option confirm off
open ftps://test\login:password@ip:port -explicit -certificate="certificate id"
lcd \\localserver\folder4$
/FTPS/folder4
synchronize local
exit
For this scenario it also works fine in case all folders are available. In case some folder is not available, for example folder2 - it experience error-message “Error changing directory to folder2” and copying all the folders 1-4 to lcd \\localserver\folder2$ (as it could not switched to subfolder). :evil:
I would like to ask if someone know the way how to create scripts that checks somehow if the folder is available and then copy the files and in case the folder is not available then do not sync data and exit.
Thank you very much in advance!
:)
As a first thing I would like to say big thank you to all who supports and develops WinSCP.
After a long time when I tried to find utility that I could use to download files from FTPS-server I choose WinSCP.
I checked the FAQ and a couple of threads on the forum, but unfortunately has not find the answer on my question.
What I have:
1) FTPS server with a known list of folders like (another names of folders cannot appear there):
/FTPS/folder1
/FTPS/folder2
/FTPS/folder3
/FTPS/folder4
2) About the server. I have no access to it and just can show how it works and what it going every day, but this cannot be changed.
Each day there are new files copied to these folders. But in case there are no new files for specific folder it became removed.
So for one it could appears like:
/FTPS/folder2
/FTPS/folder4
For another day:
/FTPS/folder1
/FTPS/folder2
/FTPS/folder3
/FTPS/folder4
What I need to do:
Download files on daily basis and copy them so separate network shared-drives.
How I’m doing this.
I see 2 ways here.
1st way:
Run the ftprun.bat file:
echo __________________________ %date% %time% ______________________________ >>log.txt
C:\ FTPS\winscp.com /script=C:\ FTPS\ftpscript.txt >>log.txt
echo.>>log.txt
ftpscript.txt:
option batch continue
option confirm off
open ftps://test\login:password@ip:port -explicit -certificate="certificate id"
lcd \\localserver\folder1$
/FTPS/folder1
synchronize local
lcd \\localserver\folder2$
/FTPS/folder2
synchronize local
lcd \\localserver\folder3$
/FTPS/folder3
synchronize local
lcd \\localserver\folder4$
/FTPS/folder4
synchronize local
exit
It works fine actually in case all 4 folders are available on the FTPS server, but in case one of them is missing, for example folder2, it experience error-message “Error changing directory to folder2” and is going synchronize /FTPS/folder1 with \\localserver\folder2$ that is incorrect. :evil:
2nd way:
Run the ftprun.bat file:
echo __________________________ %date% %time% ______________________________ >>log.txt
C:\ FTPS\winscp.com /script=C:\ FTPS\ftpscript_folder1.txt >>log.txt
C:\ FTPS\winscp.com /script=C:\ FTPS\ftpscript_folder2.txt >>log.txt
C:\ FTPS\winscp.com /script=C:\ FTPS\ftpscript_folder3.txt >>log.txt
C:\ FTPS\winscp.com /script=C:\ FTPS\ftpscript_folder4.txt >>log.txt
echo.>>log.txt
ftpscript_folder1.txt:
option batch continue
option confirm off
open ftps://test\login:password@ip:port -explicit -certificate="certificate id"
lcd \\localserver\folder1$
/FTPS/folder1
synchronize local
exit
ftpscript_folder2.txt:
option batch continue
option confirm off
open ftps://test\login:password@ip:port -explicit -certificate="certificate id"
lcd \\localserver\folder2$
/FTPS/folder2
synchronize local
exit
ftpscript_folder3.txt:
option batch continue
option confirm off
open ftps://test\login:password@ip:port -explicit -certificate="certificate id"
lcd \\localserver\folder3$
/FTPS/folder3
synchronize local
exit
ftpscript_folder4.txt:
option batch continue
option confirm off
open ftps://test\login:password@ip:port -explicit -certificate="certificate id"
lcd \\localserver\folder4$
/FTPS/folder4
synchronize local
exit
For this scenario it also works fine in case all folders are available. In case some folder is not available, for example folder2 - it experience error-message “Error changing directory to folder2” and copying all the folders 1-4 to lcd \\localserver\folder2$ (as it could not switched to subfolder). :evil:
I would like to ask if someone know the way how to create scripts that checks somehow if the folder is available and then copy the files and in case the folder is not available then do not sync data and exit.
Thank you very much in advance!
:)