Using curl to upload files - batch-file

I want to automate a file Upload to my webserver using curl. I created a batch file and used Windows Task Scheduler to execute it. When I run the batch file manually with my mouse, it sends the files to my webserver. When Windows Task Scheduler executes the batch file, it does not send files and I get error message :
'curl' is not recognized as an internal command or external, an executable program or a batch file.
curl -T C:/wamp/www/weblab/vinums/100321092.php ftp://ftp.myhost.com/anatemp/ --user user#myhost.com:mypassword

I have resolve that problem, by adding to the Windows > Control Panel > System > Advanced Settings > Environment variable
The path of curl for example : (C:\curl-7.75.0-win64-mingw\bin;)
And it works ... thanks for all

Related

FileZilla Pro CLI Batch command file not executing

I am currently attempting to use FileZilla Pro CLI on a Windows machine to connect and upload to a site in that is working in the Site Manager.
The issue is, the command below works perfectly when pasting it directly into the cmd line. However when saving it as a batch file, it simply just gets to the fzcli> prompt and then nothing happens.
The two line breaks are on purposes to override the requirement for a password and it works perfectly when pasted in.
Does anyone know if this is a cmd line issue, or if my commands need to be different to work in batch file mode?
fzcli
connect --site 0testsite01
put C:/inetpub/wwwroot/websites/sftp/files/customer/test-01.txt /test-sftp/testuser01/test/test-01-uploaded.txt
PAUSE
Your batch file executes fzcli in an interactive mode. The fzcli then waits for you to interactively enter the commands. Only after you would exit the fzcli, the batch file would continue. And fail, as it will try to execute connect as a batch file command. The fzcli does not know about the batch file. Nor does the batch file interpreter know about the fzcli commands.
It's a common misconception. You will find plenty of similar questions basically about scripting any tool that has its own commands. For example: sftp, ftp, psftp, winscp.
To provide commands to fzcli, it seems that you need to use --script switch. The fzcli documentation gives this example:
fzcli --mode standalone --script C:\Scripts\script-file

How to rename a downloaded file from within the WinSCP script?

I have WinSCP script that downloads a file from the SFTP server to the local machine. How can I rename the file from within the WinSCP script?
The script is being run from Windows machine.
The WinSCP script:
option batch off
option confirm off
open sftp://username:password#servername -hostkey=""
option transfer binary
get -latest "oldname.csv" c:\localfolder
mv c:\localfolder\oldname.csv latestname.csv
exit
I tried renaming using the commands:
rename InitialFileName FinalFileName
then tried using:
mv InitialFileName FinalFileName
But the script is throwing the error:
File not found, Language: en
Tried stuff from this blog
If you want to download the file to a different name, specify the new name directly in the get command:
get "oldname.csv" c:\localfolder\latestname.csv
(Note that when downloading one specific file, the -latest switch is pointless. The latest file out of one file[s] is that one file.)

Ignore Error Code 2 PSFTP

We have an desktop application that dynamically generates a command file to pull specific files that have the current date in the name. So in the end we have a command file that looks like this:
lcd e:\localpath
mget Filename0111.dat
mget Filenametwo0111.dat
mget Filenamethree0111.dat
bye
Where 0111 is MMDD. The command file is created via a .bat file that the desktop app executes. The application then connects to the remote server via PSFTP.exe and runs that command file to pull files.
The problem we're running into is we updated the PSFTP.exe to a newer version due to a separate issue that occurred. Now if a file is not available on the remote server it returns an error code 2 which stops the rest of the files from being retrieved. So if the first file in the list doesn't exist then it fails and the rest of the files are not downloaded.
Is there a way to ignore the error code 2 so that the rest of the files get retrieved? I had thought at first to run PSFTP.exe and it's commands through a batch file but that didn't work.
Any ideas?
PSFTP.exe has a command -be that will continue executing the batch if there is an issue.
When running a batch file, this option causes PSFTP to continue processing even if a command fails to complete successfully.
You might want this to happen if you wanted to delete a file and didn't care if it was already not present, for example.

Executing FART.exe (find and replace text) commands on remote server through SSH

I'm executing a batch file on a remote server from our build server (Jenkins) through SSH. The batch file uses fart.exe commands to find and replace text. I have placed the fart.exe in C:\Windows\System32 and I'm invoking it as C:\windows\system32\fart.exe in the batch file.
The command works perfectly fine oin the remote server, but when invoking through SSH I get an error in the Jenkins log as:
'"C:\windows\system32\fart.exe"' is not recognized as internal or external command.
This is the only error I'm getting and the other commands successfully execute in the batch script. Both of the servers are Windows Server 2012 R2.
I tried adding the path to system variable but it didn't work.
This is how the Fart.exe is used in the batch script.
for /R "%BACKUP_SOURCE%" %%G in (%ConfigFile%) do (
"C:\windows\system32\fart.exe" "%%G" %PlaceHolder% %AppPath%
)
Invoking From Jenkins
I don't think the way i invoke the batch script do matter, because it is done trough the Jenkins SSH plugin. The batch script get invoked successfully. The error i get is from when executing the Fart.exe
I tried invoking a different command of an exe located in the same path, and that is successfully invoked. so i guess the issue is isolated to FART.EXE.

FTP batch script is not exiting with error status

There is a ftp command in my batch script :
FTP -n -s:D:\scripts\Test\get.ftp
Where get.ftp contains all ftp commands including "mget abc*".
Issue here is when file(s) of names starting with abc* is not available, mget is not failing. Also, if any other ftp command fails also, the script is not exiting with error status 1. i.e. "FTP -n -s:D:\scripts\Test\get.ftp" exiting without issues.
Not able to make the batch script fail when there is no file to pick up.
Need suggestion if someone has faced similar issue.
-Krishna
The mget command works by obtaining a remote folder listing and parsing the list for the wildcard pattern that you provide. As long as the listing can be obtained successfully,
it is not considered an error if your pattern did not match any of the files on the list.
Your batch script can be setup to compare the local folder listing before and after invoking the ftp command to check if a file was downloaded. You can also use a scripted ftp solution like kermit or ftp script to be able to have more control on error reporting.

Resources