WinSCP command line for uploading file from folder named with current date - sftp

Our bank just changed the way in which upload and download files to them. Previously we could log in to a secured website, choose directory, and upload/download manually. Everything now has to be done through SFTP, using FileZilla or similar program.
I want to automate SFTP upload process by using WinSCP.
I realize I will need to use the put command line to upload. The file I'm wanting to upload is generated every day and the file name is exactly the same, but the folder being uploaded from changes. The directory structure is as such:
C:\Finance\FY 2021\YYYYMMDD\file.txt
My question is what would the upload command line look like to upload this file on a daily basis. This upload will always take place the same day, so the folder name will always be the current date in the above format.
Can these commands be contained within and run from a batch file rather than creating a batch file that merely points to a scripted txt file to run? Thanks for your help!
A follow-up question for handling of the FY YYYY part part:
Use WinSCP to upload from a folder with a fiscal year in its name to an SFTP server

WinSCP has %TIMESTAMP% syntax which you can use to refer to the folder with today's timestamp in its name.
And yes, you can specify WinSCP commands directly in the batch file using the /command parameter:
winscp.com /ini=nul /command ^
"open sftp://username:password#ftp.example.com/ -hostkey=""...""" ^
"put ""C:\Finance\FY 2021\%%TIMESTAMP#yyyymmdd%%\file.txt"" ""/remote/path/""" ^
"exit"

Related

Autosys File Watcher - looking for create date

I am wanting to setup a File Watcher job to monitor a file shared in an Active Directory environment. The filename is always the same, and does not contain the date/time. And the file stays in it's location until replaced, as others might use the file.
How can I create a File Watcher job to look for a file less than 24 hours old?
AutoSys Automation AE - Release:11.4.6.20180302-b425
There is no easy way of doing that. I would suggest, if you know when the file is created have the FT start little after the creation or deleting the file after it is processed.

Automating- Appending two text files to create 1 Excel file daily

I have two files that come in daily to a shared drive. When they are posted, they come in with the current date as part of the file name. example ( dataset1_12517.txt and dataset2_12517.txt) the next day it posts it will be (dataset1_12617.txt and so on). They are pipe delimited files if that matters.
I am trying to automate a daily merge of these two files to a single excel file that will be overwritten with each merge (file name remains the same) so my tableau dashboard can read the output without having to make a new connection daily. The tricky part is the file names will change daily, but they follow a specific naming convention.
I have access to R Studio. I have not started writing code yet so looking for a place to start or a better solution.
On a Window machine, use the copy or xcopy command lines. There are several variations on how to do it. The jist of it though is that if you supply the right switches, the source file will append to the destination file.
I like using xcopy for this. Supply the destination file name and then a list of source files.
This becomes a batch file and you can run it as a scheduled task or on demand.
This is roughly what it would look it. You may need to check the online docs to choose the right parameter switches.
xcopy C:\SRC\souce_2010235.txt newfile.txt /s
As you play with it, you may even try using a wildcard approach.
xcopy C:\SRC\*.txt newfile.txt /s
See Getting XCOPY to concatenate (append) for more details.

Uploading a file to different Unix boxes in one go

I have to upload few files from my Windows machine to different Unix boxes using WinSCP software at regular intervals.
The pain is that let's say I have 4 different Unix boxes so in WinSCP I have to open that 4 different Unix boxes individually, to upload the files.
Please advise is there any software through which I can graphically open the four Unix boxes simultaneously and upload the files to the same location?
Open 4 tabs in WinScp?
Or
Write a script to scp them from 1 on the Unix machines to the rest of the Unix machines?
Adding more info:
http://winscp.net/eng/docs/transfer_queue
http://winscp.net/eng/docs/ui_sessiontabs
Either of the two should help
Just create a batch file that connects and uploads a file to all hosts sequentially.
With WinSCP scripting the batch file can be like:
#echo off
set UPLOAD=winscp.com /command "open %%1%%" "put ""%1""" "exit" /parameter
%UPLOAD% ftp://martin:password#server1.example.com/home/martin/
%UPLOAD% sftp://user:password#server2.example.com/home/user/
Now you can call the batch file (say multiupload.bat) with a file path as an argument:
multiupload.bat c:\path\upload.txt
You can even drop/link the batch file in Explorer's "SendTo" folder to easily use it from the Explorer's "Send To" menu:
Some references:
Guide to automating file upload to SFTP server
A practical example for upload to a single host
Making the script take name of file to upload as parameter to easily reuse it.
Example for creating parametrized script to upload files:
Creating entry in Explorer's "Send To" menu.

Symfony2 - Upload, zip & encrypt a file once uploaded in the server

I have been implementing an entity in Symfony 2.2 in order to upload files to my server. I followed successfully the steps listed in
http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html
However I need to implement an additional feature, which consists in saving the file along the entity, but not the original one, but the zipped & encrypted one, same as if I'd done that using the command line of linux and then uploaded the generated zip file. I mean, when I'm required to select in my form the file, I choose it as normal, but in the server it'd be stored a zip which contains that file instead of the file itself, and of course when downloading I want the zip as well, so the name in the table has to be the one of the zip file.
I guess it could be accomplished using system calls, allowing PHP to execute a zip command over the file, but I cannot figure it out how exactly. Any help?

Unix invoke script when file is moved

I have tons of files dumped into a few different folders. I've tried organizing them several times, unfortunatly, there is no organization structure that consistently makes sense for all of them.
I finally decided to write myself an application that I can add tags to files with, then the organization can be custom to the actual organizational structure.
I want to prevent from getting orphaned data. If I move/rename a file, my tag application should be told about it so it can update the name in the database. I don't want it tagging files that no longer exist, and having to readd tags for files that used to exist.
Is there a way I can write a callback that will hook into the mv command so that if I rename or move my files, they will invoke the script, which will notify my app, which can update its database?
My app is written in Ruby, but I am willing to play with C if necessary.
If you use Linux you can use inotify (manpage) to monitor directories for file events. It seems there is a ruby interface for inotify.
From the Wikipedia:
Some of the events that can be monitored for are:
IN_ACCESS - read of the file
IN_MODIFY - last modification
IN_ATTRIB - attributes of file change
IN_OPEN and IN_CLOSE - open or close of file
IN_MOVED_FROM and IN_MOVED_TO - when the file is moved or renamed
IN_DELETE - a file/directory deleted
IN_CREATE - a file in a watched directory is created
IN_DELETE_SELF - file monitored is deleted
This does not work for Windows (and I think also not for other Unices besides Linux) as inotify does not exist there.
Can you control the path of your users? Place a script or exe and have the path point to it before the standard mv command. Have this script do what you require and then call the standard mv to perform the move.
Alternately an alias in each users profile. Have the alias call your replacement mv command.
Or rename the existing mv command and place a replacement in the same dir, call it mv and have it call your newly renamed mv command after doing what you want.

Resources