How to script and Automate

Advertisement

ashalesh
Joined:
Posts:
5
Location:
NAGPUR

How to script and Automate

Hi,

i am working on a project of SFTP.

In this I have to Download files from Multiple Folders of one Server.

But I don't know how to Script this.

The Structure of these Multiple folder And Switching from one to another is confusing.

Reply with quote

Advertisement

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

Re: How to script and Automate

Well, we do not know their structure. So unless you provide us more details and explain us, what is confusing, we can hardly help you.

Reply with quote

ashalesh
Joined:
Posts:
5
Location:
NAGPUR

Re: How to script and Automate

martin wrote:

Well, we do not know their structure. So unless you provide us more details and explain us, what is confusing, we can hardly help you.

Thanks Martin Sir, For Being helpfull.

Let me give you a little idea about the Stucture.

We Have a GMG Server

In this server there are 4 Output directories.

Now we have to copy all the files from these 4 directories to one place for furter processing.

In this I want one more customization Like Moving the copied file in sub folder Of remote directory..

I had connected to this Server Using Winscp And Made a Script Given Below.
This Copies the Files But can't move the copied file of Remote directory to Subfolder. Also How to loop this script??

open engr:engrngp@192.168.1.183
lcd d:\sftp
cd m1\done
get *.*pdf
close

open engr:engrngp@192.168.1.183
lcd d:\sftp
cd m2\done
get *.*pdf
close

open engr:engrngp@192.168.1.183
lcd d:\sftp
cd m3\done
get *.*pdf
close

open engr:engrngp@192.168.1.183
lcd d:\sftp
cd m4\done
get *.*pdf
close

Exit


this is script up to My Knowledge of Working..

Please Explore more.

Hope this will be helpfull to you.

1.jpg

Reply with quote

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

Re: How to script and Automate

1) You do not need to re-open the session for every folder.
2) I assume that *.pdf is the right mask.
2) To move the files to a subfolder, use mv *.pdf subfolder/*

open engr:engrngp@192.168.1.183

lcd d:\sftp

cd m1/done
get *.pdf
mv *.pdf subfolder/*

cd ../../m2/done
get *.pdf
mv *.pdf subfolder/*

cd ../../m3/done
get *.pdf
mv *.pdf subfolder/*

cd ../../m4/done
get *.pdf
mv *.pdf subfolder/*

exit

Reply with quote

ashalesh
Joined:
Posts:
5
Location:
NAGPUR

Re: How to script and Automate

Dear martin Sir,

Thanks for the code you provide, It works for moving the files.

But I have one issue here. If the File is already there? then It must rename it with any suffix or betterway to overwrite.

I had manually execute the command.. And it shows Following Error...

Plz help..

/m1/done
winscp> lcd d:/sftp
d:\sftp
winscp> get *.pdf
Using configured transfer settings different from factory defaults.
lk-2406-hwad-02c.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-hwad-03c.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-hwad-04c.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-tx1-01c.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-tx1-03c.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-TX1-04C.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-TX1-05C.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-tx1-06c.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-TX1-07C.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-tx1-08c-.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-TX1-08C.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-tx1-09c.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-tx1-10c-.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-TX1-10C.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-TX1-10Cnew.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-tx1-11c-.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-TX1-11C.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-tx1-12c-.pdf | 0 B | 0.0 KB/s | binary | 0%
lk-2406-TX1-12C.pdf | 0 B | 0.0 KB/s | binary | 0%
lt-2406-dak-01C.pdf | 0 B | 0.0 KB/s | binary | 0%
lt-2406-dak-03C.pdf | 0 B | 0.0 KB/s | binary | 0%
lt-2406-dak-10C.pdf | 0 B | 0.0 KB/s | binary | 0%
lt-2406-dak-12C.pdf | 0 B | 0.0 KB/s | binary | 0%
winscp> mv *.pdf 2406/*
Error moving file 'lk-2406-hwad-02c.pdf' to '2406/lk-2406-hwad-02c.pdf'.
File already exists.
Error code: 11
Error message from server (en): File already exists.
(A)bort, (R)etry, (S)kip, Ski(p) all:



Second thing i would like to ask you that, If in t he remote directory daily a new folder created with Today's Date..

Can we script it with Date to access that folder?

Please answer..

Reply with quote

Advertisement

ashalesh
Joined:
Posts:
5
Location:
NAGPUR

Moification in Script

Hello Sir,

After a long time I need your help.

The last when you helped, It works

Now I want to modify this script.

# moving remote files after sucessful download.
option batch on
option confirm off
# Connect
open ftp:buti:buti123@192.168.1.183
option transfer binary
#Change local Directory
lcd D:\BUTITEST\M1
cd /test1/M1
get *.pdf
mv *.pdf Done/*

#Disconnect
exit


here I want to List the files which are available in that folder,

and after transfer it should move only listed files to Done folder.

If any new file appear while session is on, It must skip it and run in next session.

pls help

Reply with quote

ashalesh
Joined:
Posts:
5
Location:
NAGPUR

Re: Moification in Script

Dear Martin Sir,

Thanks for your reply.

As you mentioned, I am trying to Make it in powershell.

In Powershell, I am successful upto Copy and move files.
But as mentioned earlier, I am trying to Skip the newly appeared file to move during the session.

that Newly appeared file moved directly to Backup without copying.

pls help

Reply with quote

Advertisement

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

Re: Moification in Script

ashalesh wrote:

But as mentioned earlier, I am trying to Skip the newly appeared file to move during the session.
That's what the code does.
It moves only the files that were really transferred.
Read the code!

Reply with quote

Advertisement

You can post new topics in this forum