1

I'm trying to upload latest files generated in one hour to a remote server. But the script I wrote is intelligent enough to gather only the latest file in directory and upload it to FTP. Any chance of set the variable type as array and upload the files in the array?

My FTP batch file:

FOR /F %%I IN ('DIR "abcdef*.bac" /B /O:D') DO SET latest_file=%%I

echo user domain/username> ftp.txt
echo password>> ftp.txt
echo cd remotepath>> ftp.txt
echo put %latest_file%>>ftp.txt
echo quit>> ftp.txt

ftp -n -s ftp.txt Servername>ftp_logs.txt

del ftp.txt
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
User412387
  • 79
  • 1
  • 11
  • Take a look at [this](https://stackoverflow.com/questions/17605767/create-list-or-arrays-in-windows-batch) post, it might help you in what you want. – dcg Jun 13 '17 at 12:37

1 Answers1

1

It would be difficult to write this in a pure batch file code.

You better use some more powerful tool.

For example with WinSCP FTP client, it's trivial:

winscp.com /ini=nul /log=upload.log /command ^
    "open ftp://username:password@ftp.example.com/" ^
    "put -filemask=>1H C:\local\path\abcdef*.bac /remote/path/" ^
    "exit"

References:

(I'm the author of WinSCP)

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992