Topic "How to script and Automate"

Author Message
ashalesh
[View user's profile]

Joined: 2016-06-17
Posts: 3
Location: NAGPUR
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.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
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.
ashalesh
[View user's profile]

Joined: 2016-06-17
Posts: 3
Location: NAGPUR
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 (305.74 KB) [Download]

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
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/*

Code:
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
ashalesh
[View user's profile]

Joined: 2016-06-17
Posts: 3
Location: NAGPUR
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..
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
You cannot force WinSCP to rename a file over an existing file.
Cannot you just delete the target folder contents beforehand? rm 2406/*

To use a timestamp in the script you can use a syntax like %TIMESTAMP#yyyy-mm-dd
See https://winscp.net/eng/docs/scripting#timestamp
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