Download files to local and delete after with notification automatically

Advertisement

matt3m
Joined:
Posts:
10
Location:
UK

Download files to local and delete after with notification automatically

Hi all,

I am trying to automate the downloading from my server to my local computer - I'm not familiar with scripting but I have followed this YouTube video - https://www.youtube.com/watch?v=ndvEYOQLc4c which works but I would also like it to delete the file from the server when it has successfully downloaded to my local computer and if possible get some sort of notification to let me know the files downloaded and that they have been successful.

I saw this .NET script - https://winscp.net/eng/docs/library_example_delete_after_successful_download which worked to begin with when I was running it with a testing folder but since I changed it to the main folder it no longer works for some reason.

Anyway, is there a way for me to automate downloading of files which when completed they get deleted from the server and I then receive some form of notification to let me know what files have been downloaded? Also I would want this to be one way.

Thanks

Matt

Reply with quote

Advertisement

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

Re: Download files to local and delete after with notification automatically

matt3m wrote:

Anyway, is there a way for me to automate downloading of files which when completed they get deleted from the server
Well, there's the way that you have found:
https://winscp.net/eng/docs/library_example_delete_after_successful_download
Though that's a very specific code, which may be unnecessarily complicated for your task.
See this:
https://winscp.net/eng/docs/faq_delete_synchronized_files

I then receive some form of notification to let me know what files have been downloaded?
That's quite vague. But maybe this will help you:
https://winscp.net/eng/docs/script_email

Reply with quote

matt3m
Joined:
Posts:
10
Location:
UK

Hi Martin,

Thanks for the reply.

Sorry for being vague about the notifications, I'm not good with scripting, it's a bit of a try this and hope it works situation. I was just thinking I could get a notification whether that's an email, prompt on my computer or something like that that can let me know all the files downloaded, similar to how Pushover works.

I'll be honest I will struggle to get this working with the documentation. I do have one script working from the YouTube video but that doesn't delete the files, is it possible to edit the script from the YouTube video to delete the files or does it need to be .NET?

Any help would be appreciated :)

Thanks

Regards

Matt

Reply with quote

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

matt3m wrote:

Sorry for being vague about the notifications, I'm not good with scripting, it's a bit of a try this and hope it works situation. I was just thinking I could get a notification whether that's an email, prompt on my computer or something like that that can let me know all the files downloaded, similar to how Pushover works.
WinSCP does not do any notification on its own. All it does, is that it reports its result using its exit code. You can use the exit code to decide what notification to send using any 3rd party tool you like. As shown by the already linked example:
https://winscp.net/eng/docs/script_email

I'll be honest I will struggle to get this working with the documentation. I do have one script working from the YouTube video but that doesn't delete the files, is it possible to edit the script from the YouTube video to delete the files or does it need to be .NET?
It does not have to be .NET, you can probably do with simply adding the -delete switch. Again, as shown in the article I've already linked:
https://winscp.net/eng/docs/faq_delete_synchronized_files#moving

Reply with quote

matt3m
Joined:
Posts:
10
Location:
UK

Hi martin,

Thanks for your reply :)

I did try using -delete but it didn't seem to work so instead I have used the following
rmdir "remote folder" mkdir "remote folder"
and it seems to work fine.

I think I will leave the notification thing as it looks too complicated for me.

Thanks for all the help.

Reply with quote

Advertisement

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

matt3m wrote:

I did try using -delete but it didn't seem to work
Can you post a log file for that?

so instead I have used the following
rmdir "remote folder" mkdir "remote folder"
and it seems to work fine.
OK, but that's not transactionally safe (you can lose a file, if it is created between get and rmdir).

Reply with quote

matt3m
Joined:
Posts:
10
Location:
UK

martin wrote:

Can you post a log file for that?
Hi martin,

How do I get a log file? I'm new to all of this.

Also, I'm using synchronize local instead of get is that still not safe to do?

Thanks

Matt

Reply with quote

matt3m
Joined:
Posts:
10
Location:
UK

Hi Martin,

I have adjusted the script and the files download but instead of deleting the files it deletes the folder - have I done something wrong? Here's the script I'm using...
option batch abort
option confirm off
open sftp://username:password@serveraddress.com -hostkey="ssh-rsa 2048 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx username@serveraddress"
get -delete "server/Work Files" "D:\Work Files"
 
exit
Thanks
Matt

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum