How to move local file to another local folder after sending to mainframe via FTP using batch command - windows

I have a local file upload routine, via ftp, to a mainframe using a simple .BAT file, after successfully sending this file it should be moved to another local directory, how can I automate this process? In case of error could just pause script execution
I use two bat files, SEND.BAT and CONFIG.BAT, i run only the SEND.bat;
SEND.bat
ftp -s:CONFIG.bat X.X.X.X
pause
CONFIG.bat
USER
PASSWORD
CD B.A01
put \\SERVER.contoso.com\FOLDER\*.txt RETORNO(+1)
put \\SERVER.contoso.com\FOLDER\*.txt COMPROV(+1)
disconnect
bye
After successfully submitting, how could I automatically move these files to a respective local folder in case the mainframe return code is
250 send sucessfully
And if the mainframe return is
Not connected
or
Failed
just pause the command with Pause. Is it possible to send an email warning of both situations or open a website (this website already exists and will call my phone)? Using only bat commands in Windows?
Thanks for help!

Related

How to execute further batch file commands after running "ftp" commands contains in the batch file itself

I have a .bat document where I do some operations with FTP. I want to end the FTP connection and get to finish with the terminal on the desired directory.
I'm trying this, but when it gets to quit, it stops.
cd %USERPROFILE%\Foilder\project\angular
call ng build
#FTP -i -s:"%~f0"&GOTO:EOF
open connection
user
password
cd httpdocs/project
mdelete *.woff
quit
cd %USERPROFILE%\Foilder\Subfolder
It gives me this message right after doing the quit and never runs the next line.
221 Goodbye.
Ideal scenario, run this last cd command and have the terminal ready on the folder that I want to run it. Thing is that I have to do some uploads to two different FTP servers and it would be great to have the console finishing in the folder where I run "dev.bat" to get it to work
Is it possible to do this?
Your script uses a known hack that allows you to specify ftp commands directly in the batch file.
The %~f0 is replaced with the path to the batch file itself. So the ftp -s:%~f0 runs ftp and tells it to use the batch file itself as ftp script file. You have probably noticed that it results in couple of errors, as ftp fails on the first few lines of the batch file, which are not valid ftp commands (the cd ..., call ... and ftp ...).
Equivalently, the batch file would try to run all commands after ftp ... once ftp finishes, also failing, as those are not valid batch file commands. To avoid that, the hack uses GOTO:EOF to skip the rest of the batch file (EOF=eof of the file).
While you actually want to execute some commands after the ftp. At least the cd command. So do not skip the rest of the batch file. Skip only the ftp commands:
ftp -i -s:"%~f0"&goto AFTER_FTP
(ftp commands)
quit
:AFTER_FTP
cd %USERPROFILE%\Foilder\Subfolder
Note the # before ftp. That (and the GOTO:EOF) are clear signs, that the script you based your batch file on, was designed to start with ftp on the very first line and contain nothing else, but the ftp commands. You have deviated from that.
Alternatively, use some more capable FTP client that allows specifying the commands on its command-line without hacks.
For example with my WinSCP FTP client, you can do:
cd %USERPROFILE%\Foilder\project\angular
call ng build
winscp.com /ini=nul /command ^
"open ftp://user:password#connection/" ^
"cd httpdocs/project" ^
"rm *.woff" ^
"exit"
cd %USERPROFILE%\Foilder\Subfolder
There's a guide for converting Windows ftp script to WinSCP script.

Is their a way to synchronise a directory on a raspberry pi to a laptop using WinSCP

I want to be able to synchronize a directory between my Windows laptop and raspberry pi using WinSCP. By "synchronize" I mean if a file is created in the directory by my raspberry pi, it is automatically placed in predefined directory on my laptop.
I have already set up a WinSCP connection between these two devices.
I was following along using this tutorial https://www.youtube.com/watch?v=ndvEYOQLc4c however I reliazed that this was for an FTP server and I also could not save the .bat file or code file into the appropriate directory as it has it has an administrator lock, so I assume that the method is only for FTB servers.
Edit
I have given myself permissions to save the code files in the appropriate places, however I now receive the error
Host "lynn-vs2.cloudapp.net" does not exist.
Whenever I run the bat file:
winscp.com /script=SyncToLocalScript.txt
pause
Which in turn runs the txt file:
option batch abort
option confirm off
open sftp://sftpuser04:password123!#lynn-vs2.cloudapp.net -hostkey="ssh-ed25519 256 00:69:55:c8:a8:84:01:6d:7c:ff:9f:8c:89:b3:7d:67"
synchronize local C:\Users\****\OneDrive\Desktop\RaspPCAP /home/pi/Desktop/PCapFiles
exit
I am not sure what "lynn-vs2.cloudapp.net" is.

Can't transfer files using FTP script and batch on Windows

I have a folder with PDF files locally on hard disk and I want to upload files from this folder to an FTP server.
So I created a batch file that should upload PDF files to the FTP server. Everything seems to work fine and the console window displays File successfully transferred, but actually no file really uploaded.
The FTP script content:
open
000.000.000.000 -- not the real ftp server ip lol
bla#nirlatpro.com
PASSWORD
mput c:\Batch\*.pdf
quit
Command window with output on running this script:
It looks like it works, but no file is actually uploaded.
What is even more strange is if I connect to FTP using GUI application and drag the files, it does work and all the files are uploaded to the server.
summary:
- It's works fine if i'm using windows explore and dragg the files.
- It's not uploading the files if i'm using cmd commands or batch script with ftp file, even if the console window displays 'File successfully transferred'
it was a permissions problem
apparently the ftp server does not allowing to copy files in to the root directory /
console window display it "Current restricted directory is / "
I too Faced a similar problem downloading a file from ftp through command line, But every time my request was rejected and my connection was not established.
After a thorough research i found the t i need to do settings in the IIS for ftp.
Steps:
1) Set your IIS Server on.
a:Goto control panel-->Programs&Features-->Turn windows Features on or off-->Internet Information Services.
b: Expand the Internet Information services-->Check FTP services-->Expand FTP Server-->FTP Service (Check it)-->press OK.
2)Open IIS Manager(win+r-->inetmgr)
a: Select FTP authentication-->Enable Anonymous Authentication or Base Authentication (as per your requirement).
b: Select FTP Authorization-->Select All users, give permissions (read or write or both) & press ok.
c) Open FTP Directory Browsing select MS-DOS for windows Server or Unix for Unix server.
3) Finally goto Services.msc(win+r-->'services.msc')-->MicrosoftFTPServices-->restart.
Now goto your command prompt and write your respective code for ftp it will work.

Implicit TLS FTP connection using WinSCP or other command line FTP client in Windows

I need to connect to an FTP secured with implicit TLS, username and password from the command line so that I can create a batch later on. I am using WinSCP since it's the most popular (I think) or the one that I can use to achieve this according to extensive googling. I'm not an expert but reading the documentation I have this so far with unsuccessful connection from command prompt:
winscp> open username:password#host:port -implicit -certificate="aa:aa:aa:aa..."
Once connected I need to extract everything there to a folder \hostname\folder or c:\folder then delete the files on the ftp (more or less like cut)
Thanks to Martin Prikryl correction I was able to connect, here is what I did:
Created a text file with the winscp.com commands "connection.txt":
# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect with username and password
open ftp://username:password#host:port -implicit -certificate="aa:aa:aa:aa...."
# Change local directory
lcd C:\local_working_folder
# Force binary mode transfer
option transfer binary
# Download missing files to local directory from remote
synchronize local
# Delete all remote files
rm *
# Disconnect
close
# Exit WinSCP
exit
Now from command prompt or in a batch file you just call winscp.exe from where it is installed. If from installation media it should be C:\Program Files\WinSCP\WinSCP.exe of if extracted from a .zip portable version point to the folder where you extracted the file:
C:\WinSCP\WinSCP.exe /console /script="connection.txt" /log="conn.log"
Then just schedule the batch to automate the process.
Your syntax is almost correct. You are missing only the protocol prefix ftp:// (note that WinSCP defaults to the SFTP protocol).
open ftp://username:password#host:port -implicit -certificate="aa:aa:aa:aa..."
For details see:
https://winscp.net/eng/docs/session_url
https://winscp.net/eng/docs/scriptcommand_open
If that does not help, you need to share with us a script log file or at least an error message.

windows batch file to copy a file from a server to local

I would like to write a little code that copy on a local pc a file from another (a server).
Which Windows batch file function I can use to write this little batch file program, (FTP maybe?)
And also to visualize a message on my pc (the local pc)
thanks for all
Just use wget.
It can be called from your batch file and will download from HTTP and FTP.
Write SHUTDOWN -i in a note pad then save to desktop and name it anything but it must have .bat at the end and then click save and u can shutdown any computer in you server.

Resources