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: *FIXED* 301 Moved Permently

Add a slash to the target path:
mv test.txt /home/eg/archiv/
Rawptor

*FIXED* 301 Moved Permently

Hey Guys,
I'm working with WinSCP a few days and had my problems to write a batch script but finally I could connect successfully to WebDAV service. Now I can't move files in my batch script from remote directory /home/eg/data to remote /home/eg/archiv. It says
Error at moving File 'test.txt' to '/home/eg/archiv'
301 Moved Permanently

My script:
@echo off
"U:\03_IT\0300_Administration\03_Portable\WinSCP\WinSCP.com" ^
  /log="U:\03_IT\0300_Administration\03_Portable\WinSCP\log\WINSCPLog.txt" /ini=nul ^
  /command ^
    "option batch abort"^
    "option confirm off"^
    "open davs://username:password@connection.de/home/eg/data -certificate=""xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx""" ^
    "lcd ::UNC Path:: \\test\testing\example"^
    "get test.tab" ^
    "mv test.txt /home/eg/archiv"^ # remote directory
    "exit"
 
PAUSE


*EDIT FIXED*
I missed one / at the mv parameter
Fixed command
  "mv test.txt /home/eg/archiv/"^

Kind regards
Rudi
martin

Re: Answered it myself BUT could use advice!

You can exclude the Archive folder from get command using -filemask=|Archive/.
https://winscp.net/eng/docs/scriptcommand_get#filemask
Though that not possible with mv. And even if it was, it won't be transactionally safe. What if a file is added just between get and mv?
For transactionally safe solution, you better use WinSCP .NET assembly.
There's an example for upload:
https://winscp.net/eng/docs/script_local_move_after_successful_upload
Converting it to download should be trivial.

Anyway, if you want to stick with simple scripting, one trick is to use *.?* instead of *.*. That will match only files (and folders) which have some extension (so not Archive).
roleki

Answered it myself BUT could use advice!

I found the mv command and that does what I need it to
# ftpfromXYZ.txt 
option batch on
option confirm off
open sftp://username:Password@partner.site.com:22
get -resume *.txt "\\Local-srv\Secure$\Downloads\XYZ\"
get -resume *.xlsx "\\Local-srv\Secure$\Downloads\XYZ\"
mv *.txt Archive/
mv *.xlsx Archive/
close
exit

But say one day they stick a *.csv in the root; how would I download ALL files EXCEPT the Archive directory, and move all files regardless of format to the Archive directory when done? How would I make sure I successfully copied the file first? I'm new to this, sorry!
roleki

Move Remote Files Via Batch/Script

One of our FTP partners dumps .txt and .xlsx files to a root directory; when we have finished grabbing the files they have dumped, we move them to an Archive directory under root.

Currently we do all this in the WinSCP GUI, but I would like to automate this process, and I have got it to where I can pull the files without trouble using a batch file and Task Scheduler, but I have a problem:

I don't know how to move files on the remote server into the Archive folder to show them we have retrieved these.

This is the text file I have set up so far, which is called by the .bat file by Task Scheduler.
# ftpfromXYZ.txt
option batch on
option confirm off
open sftp://username:Password@partner.site.com:22
get -resume *.txt "\\Local-srv\Secure$\Downloads\XYZ\"
get -resume *.xlsx "\\Local-srv\Secure$\Downloads\XYZ\"
close
exit

Any ideas how I would move a wildcard file to a directory under root on the source server?