Topic "Get files from Host, and rename on Server"

Author Message
SalientAnimal

Guest


Hi All,

I want to automate the process of getting files from an external FTP site, as doing this manually daily is quite tedious.

The files are created daily, and only a part of the file name remains consistent each day. There are 5 files, that need to be fetched every single day (Monday - Sunday) from an external FTP server.

At this point in time, I have absolutely no idea where to start, except for knowing that my best bet would probably be to create a batch file, and to have it execute the required script.

Could someone please talk me through how I go about creating a script that will do the following:
Get the 5 files from the external server daily
Rename the files on the destination server daily
Move the source files into a "downloaded folder" on the source server
Move the files on destination server to a "imported directory" only at the end of the day, renaming them by adding a time stamp to the file name.

I would really appreciate as much help as possible here, as I don't have a lot of time to get this setup, and I am unfortunately not making much sense of the WinSCP documentation.

I am running a Windows Server

Thanks.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24552
Location: Prague, Czechia
Sorry, but this is not a core writing service.

Please start here:
https://winscp.net/eng/docs/guide_automation
https://winscp.net/eng/docs/guide_schedule

And if you have a specific problem, ask a specific question.
SalientAnimal

Guest


I have creating my script file in a text file as per the documents.

The part that I wasn't 100% sure of was when the file was being downloaded, is wasn't downloading the files as they were on the server. I had made a minor error on in my script which I have since figured out.

The part I haven't started working on, is how to, once the file is on my server, and once it has been "processed" to then be moved to another directory and renamed.

I would assume though, that I would require more than one text file, and that they would need to be executed by two different .bat files.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24552
Location: Prague, Czechia
You do not need two different scripts for this. Just use the mv command after the get.

Though note that this is not transactional. What, if a new file is added between the download and the move?

You can do this:
- Move the files before download to some temporary remote folder
- Download the files from there
- Move the files from the temporary folder to the archive folder

Or use WinSCP .NET assembly from PowerShell script. This will allow you to enumerate and move only the files that were really downloaded.
See these similar examples:
https://winscp.net/eng/docs/library_example_delete_after_successful_download
https://winscp.net/eng/docs/script_local_move_after_successful_upload
SalientAnimal

Guest


The new files are only created once a day. Which is why I download them daily. After which I then need to somehow move the original files on the FTP server into a backup directory.
Advertisements

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!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License