Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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!
ashalesh

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
martin

Re: Moification in Script

ashalesh wrote:

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.

This is difficult to do with a simple scripting.
You better switch to WinSCP .NET assembly (and PowerShell).
See https://stackoverflow.com/q/48311614/850848
ashalesh

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:[email protected]
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
martin

Re: How to script and Automate

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://beta.winscp.net/eng/docs/scripting#timestamp
ashalesh

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..
martin

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:[email protected]


lcd d:\sftp

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

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

cd ../../m3/done