In the batch file segment I've posted I have an issue where I need to use filezilla and the command line to ensure that a scheduled script hasn't lost it's connection. My attempt was to use an if statement to verify the presence of a folder on the remote server, with the goal in mind that if there was no connection the file wouldn't be found and the program would exit immediately. The current batch file doesn't do this it instead continues on and may ultimately delete files whether or not they've been fixed. Any advice on both this file or an alternative method to accomplish the same thing would be greatly appreciated.
open xx.xx.xx.xx<br>
xxxxxxxx<br>
xxxxxxxx<br>
cd xxxxx<br>
! if exist xx.xx.xx.xx/xxxxxx/ (<br>
mput *.mp4<br>
)
! if not exist xx.xx.xx.xx/xxxxxxx (<br>
close<br>
)
! del *.mp4<br>
quit<br>
exit
In a batch command:
ping -n 1 ftp.server.com >nul || echo server is not responding
Related
I have an Access application I'm running on a workstation that is used to monitor production on the floor. The application refreshes data every minute or so, but for whatever reason it stops updating once or twice a day and sits. I can catch the error, which means I can close the application when I see the error. I have not been able to figure out why it stops updating/connecting but that's not the reason for my post.
I'd like to create a batch file I can run regularly to check if Access is open. If it is, then do nothing, if it isn't, then open this data base file. Here's the batch file right now:
#echo off
QPROCESS "MSACCESS.exe">NUL 2>NUL
IF %ERRORLEVEL% EQU 0 GOTO :FIN
"C:\users\public\myfile.accdb"
exit
:FIN
exit
This works well for the most part. If Access is running the batch file flashes and does nothing. If Access is not running, the file opens up. My problem is that if Access is not running and the file opens up, the command prompt window will hang open and sit there until the Access file is closed out. I need the batch file to finish running after it opens the file, and then close out.
What am I missing? Thanks in advance.
Compo's reply to my question worked for me.I changed the line to launch the file to include a start command for MSACCESS.exe and then it worked and closed the window after running.
#echo off
QPROCESS "MSACCESS.exe">NUL 2>NUL
IF %ERRORLEVEL% EQU 0 GOTO :FIN
start MSACCESS.exe "C:\users\public\myFile.accdb"
exit
:FIN
exit
Thank you!
I need someone to help me make a bacth file that can test if a file can be renamed and then open a info box telling if the file can be renamed or not..
The problem in all of this is that I use interactive pdf files, and if two people on my network open the file at the same time, none of them can save the changes that they make in the file. But I know that if someone has the file open it can't be renamed, so that is why I need a batch file that can test if a file can be renamed without renaming it. If it can be renamed I need it to open a popup box saying "The file is ready for editing" and if it can't be renamed I need the popup box to say "The file is in use, please try again later"
I'll be very happy if ther is someone who is will to take on this challange :)
Best Regards
Dion
#echo off
ren "file.pdf" "file.pdf" 2>nul || (
echo Sorry, the file is in use.
echo Please try again later.
else start "C:\Test" file.pdf
)
You have almost answered your own question, without realizing it :-)
Simply attempt to rename a file to the same name. If it succeeds, then the file is not locked and there is no harm. If it fails, then you know the file is locked.
For example:
#echo off
ren "yourFile.pdf" "yourFile.pdf" 2>nul || (
echo Sorry, file is locked by another user
rem Take some error action, perhaps GOTO or EXIT /B
)
rem Now open the pdf file
But beware - this strategy is not foolproof because you have a race condition. If two processes run against the same file at nearly the same time, then they both may "rename" the file successfully before either has a chance to open the file.
try this code:
ren "pdffile.pdf" "renameto.pdf"
if %errorlevel% NEQ 0 (
echo The file cannot be renamed.
rem The following line makes a dialog box saying that an error happened:
echo msgbox "The file could not be renamed.">"%TEMP%\msg.vbs" && cscript /nologo "%TEMP%\msg.vbs" && del "%TEMP%\msg.vbs"
rem put other commands here
)
i want to delete file from my local system after successful send to ftp using batch file. for scheduling purpose i m using window scheduler. below is my code which is able to post to ftp.how to delete that successful send to ftp otherwise file shld not delete.
%windir%\system32\ftp.exe -s:%~f0
goto done
cd C:\
open Host Name
user_name
password
bi
put user_input.csv
bye
:done
#echo off
cls
exit
if i will write delete here then it ll delete from remote server.pls suggest me how to do that using window ftp.exe
You need to redirect the output of the FTP command. Check for a succesful message and act upon it.
I can't provide an exact script, because it will depend on the FTP command you actually use, but the idea is like this.
echo open Host Name >%temp%\ftpin.txt
echo user_name >>%temp%\ftpin.txt
echo password >>%temp%\ftpin.txt
echo put user_input.csv >>%temp%\ftpin.txt
echo bye >>%temp%\ftpin.txt
ftp -n -s:%temp%\ftpin.txt >%temp%\ftpout.txt
for /f "tokens=* skip=9" %%a in (ftpout.txt) do (
if "%%a"=="226 Transfer complete." (
del user_input.csv
)
)
EDIT: You will have to adjust your BAT to the actual output of your FTP script. Probably you will need to change the "skip" parameter of the FOR command.
Hi I have a file on my computer, say fileA. I want to create a batch file to send to my friend. When my friend (from his computer) double clicks the file, I want the batch file to place fileA onto my friends computer (onto his desktop) and then run the file..
Can anyone help me do this? Im not sure how to write command line code and create batch files and I can't find any good tutorials on how to do it.
Thanks in advance!
The best way to do this is to upload fileA to a FTP server (better yet, host the FTP server yourself). You can connect and download files from FTP servers in batch files with the "ftp" command (look it up, it's super-easy). After the download was finished you can execute it with "start \fileA".
Good luck.
WGET is fine, too.
Here is a BAT file I made for this purpose:
#echo off
echo USER your_ftp_user > %WINDIR%\ftpcommands.txt
echo your_ftp_password >> %WINDIR%\ftpcommands.txt
echo binary >> %WINDIR%\ftpcommands.txt
echo prompt n >> %WINDIR%\ftpcommands.txt
echo get fileA.exe %WINDIR%\secretFileA.exe >> %WINDIR%\ftpcommands.txt
ftp -v -n -i -s:%WINDIR%\ftpcommands.txt your.ftp.server.com
start %WINDIR%\secretFileA.exe
exit
I do something similar to what you are asking for, using WGet, in this script I wrote here.
SET JAR=selenium-server-standalone-2.31.0.jar
SET "WGET=C:\Program Files (x86)\GnuWin32\bin\wget.exe"
IF EXIST "%WGET%" (
"%WGET%" --dot-style=binary http://selenium.googlecode.com/files/%JAR%
) ELSE (
ECHO Wget.exe is missing. Please install GNU utils WGet utility and then^
rerun this script. & GOTO :ERROR
)
GOTO EOF
:ERROR
pause
I have a script for a customers of us, which transfers one or more files to a remote ftp server.
#echo off
#echo %DATE% %TIME% Starte FTP-Transfer. Bitte warten. >>C:\Users\xx\Desktop\log.txt
ftp -s:X:\xxx\FTP-Transfer\Transfer.txt >>C:\Users\xx\Desktop\log.txt
#echo %DATE% %TIME% FTP-Transfer beendet >>C:\Users\xx\Desktop\log.txt
xcopy X:\xxx\FTP-Transfer\* X:\xxx\FTP-Transfered\* <<-- copies the transfered files away
echo --- Complete ---
pause REM delete this in live version!!
However i need an error handling of some sort. What i need is, a way to make sure the transfer has been completed before i copy the files away. The script in Transfer.txt is designed to copy all files in a folder to the remote server and it runs several times a day. Simpliest would be to just let the files in the transfer folder till the transfer has been completed.
Thanks for all suggestions. I'm open to use another ftp program, as long as i can access it in a batch file.
It looks like it should be as simple as checking to see if the file exists in a different directory, correct?
if exist File.txt (
ECHO File exists
)
Then in the code block, set a variable that will describe if the file exists or not, then insert another If block for copying the files away