Androgyny Rocks
Androgyny Rocks

Reputation: 31

Batch file when using WinSCP and command prompt

I am currently writing a script that calls WinSCP, connects an SFTP session, transfers a group of files from a local server to a remote server, closes the connection, then moves the local file to an archive. An alternate acceptable solution would be to copy the file to archive and then delete it from the source directory.

The problem I am having is that I can get WinSCP to open, connect and transfer the files, but after that the commands are ignored and I am unable to automate the connection close, file move or copy and the deletion and closing of command prompt. What is the best way to do this?

My FTP.bat file that connects the session and calls the script -

"C:\Program Files\WinSCP\WinSCP.exe" /console /command "lcd d:\bofa_ftp\out" /script=script.txt [email protected]

My script file that puts the file and closes the connection -

option batch abort
option confirm off
option exclude script.txt
put *.txt
close

When I add any commands to either the bat or the script they are ignored.

Upvotes: 1

Views: 16630

Answers (2)

Martin Prikryl
Martin Prikryl

Reputation: 202682

Commands after close are definitely not ignored. Your problem might be that you are trying to put Windows commands to WinSCP script. Note that there are no commands in WinSCP to move local files.

Upvotes: 2

Krishna
Krishna

Reputation: 11

Instead of trying using Winscp3, try with plink.exe.

Plink is the best option to transfer files from winscp3 to your local.By using scp command we can transfer file from winscp to local as well as one folder in to another folder in winscp.

scp [email protected]:/data/tmp/samplscp.txt [email protected]:/data/tmp/dir/tech

Please refer to: http://99students.com/move-files-in-unix/

Upvotes: -1

Related Questions