I'm moving a task from manual to automatic
I'm well aware that you can't check for errors when doing this, but that's not my goal.
My code works as expected, but I'm missing... something
I need to let the user know that after I've put the file in the FTP location, that it was uploaded and they no longer need to wait for the file.
I've done this up to now by blagging the user, once the command has run, they just get told it's worked
#echo off
REM Generates the script
echo open 000.000.000.000> temp.txt
echo username>> temp.txt
echo password>> temp.txt
echo lcd "N:\line\line\line">> temp.txt
echo put file.txt>> temp.txt
echo quit>> temp.txt
REM Open FTP and run the script above
ftp -s:temp.txt
REM Remove the temp file
del temp.txt
REM Display confirmation
msg %username% "File sent to FTP"
Any help is greatly appreciated. I will add any more info if needed
You have to download the file back to see if it was correctly uploaded and do fc.
For unattened file download via ftp look at robvanderwoude's ftp. Don't forget that when saving the downloaded file it should have different name than the one you were uploading originally.
Then simply compare the files you have via fc command like this:
#echo off
fc c:\temp.txt r:\temp_to_check.txt > nul
if errorlevel 1 goto error
goto :EOF
:error
echo "The file was uploaded and downloaded incorrectly"
Answer specific to my question for visual purposes:
REM Open FTP and run the script above
ftp -s:temp.txt
REM File check
fc "N:\line\line\TEST.TXT" "N:\line\line\check_location\TEST.TXT" > nul
if errorlevel 1 goto error
REM Remove the temp file
del temp.txt
REM Display confirmation
msg %username% "File has now been sent to FTP"
goto :EOF
:error
msg "The file was uploaded or downloaded incorrectly"
Related
Hello i was trying to download a .rar archive on mediafire but it doesnt seem to work it the file doesnt get to the specific folder
"c:\potato"
Here is my code:
#Echo off
echo download press any key
pause
bitsadmin.exe /transfer "JobName"
http://download1142.mediafire.com/sxd533x3fosg/ymr5y2r0yax2fx8/minecraft+generator.zip C:\Potato.exe
pause
Try something like this:
#echo off
setlocal EnableDelayedExpansion
set "infile=http://download1142.mediafire.com/3b1mz9yb72tg/ymr5y2r0yax2fx8/minecraft+generator.zip"
set "outfile=Potato.zip"
cd "C:\"
echo download press any key
pause
powershell.exe -Command (new-object System.Net.WebClient).DownloadFile('"%infile%"','"%outfile%"') | findstr "Exception error" >nul 2>nul
set "downloadComplete=%errorlevel%"
if %downloadComplete% neq 1 echo Something went wrong, please try again
if %downloadComplete% neq 1 pause
if %downloadComplete% neq 1 goto :eof
unzip "%outfile%" "minecraft generator.zip" >nul
unzip "minecraft generator.zip" "minecraft generator.exe" >nul
rename "minecraft generator.exe" "potato.exe"
pause
Please note that you used the mediafire URL instead of the actual file URL, and that you try to download a zip file to .exe. You should first download the file as zip, and then use unzip to unzip the files.
Also note that your second zip seems to be password protected.
I want to know how to check if FTP directory exists, using a batch dos or command.
PS:
Obviously I do not need the root of the server, but a subdirectory, otherwise I would have been enough ping it.
thanks
You could use an ftp script that tries to change to the directory and then parse the output looking for the 550 error code that says you cannot. Something like the following works for me...
#Echo off
echo open ftp.mysite.com>test.ftp
echo ftpusername>>test.ftp
echo ftppassword>>test.ftp
echo cd %1>>test.ftp
echo quit>>test.ftp
for /f %%i in ('ftp -s:test.ftp') do if {%%i} EQU {550} echo Does not exist
I have a program in my FTP server to generate a file, which may take 3-5 minutes to complete and also I knew the name of the file which i being created by my program. Now, once I initiate the program in my server, I have keep checking until the file is created. Once it is created, I am using the below batch script to ftp the file to my local desktop.
#ftp -i -s:"%~f0"&GOTO:EOF
open 10.100.16.111
username
password
lcd c:\
cd root/output_folder
binary
mget "*partial_file_name*" REM mget using wildcard search
disconnect
bye
This script works fine for me. But the problem is, I need modify this script as such, script should keep running until the file is generated. Because i don't know when the file creation will get completed. So, it will great if some one help/guide me to make a looping script which will wait until the completion of file creation and download the same file through FTP.
With this edit you can launch the batch file with the file name on the command line, like this:
ftpscript.bat "filename.ext"
Note that your lcd uses c:\ which is a restricted location in later versions of windows.
#echo off
>file.tmp echo open 10.100.16.111
>>file.tmp echo username
>>file.tmp echo password
>>file.tmp echo lcd c:\
>>file.tmp echo cd root/output_folder
>>file.tmp echo binary
>>file.tmp echo mget "%~1"
>>file.tmp echo disconnect
>>file.tmp echo bye
:retry
ftp -i -s:"file.tmp"
if not exist "%~1" timeout /t 300 & goto :retry
echo file has downloaded
del file.tmp
pause
More elegant solution is to use an FTP client that supports parametrized scripts or commands on command-line, such as WinSCP, to avoid creating a temporary script file.
Parametrized script
The batch file would be more or less identical as with the Windows ftp:
#echo off
:retry
winscp.com /script=script.txt /parameter "%~1"
if not exist "%~1" timeout /t 300 & goto :retry
echo file has downloaded
pause
The ftp script converts to following WinSCP script:
open ftp://username:password#10.100.16.111/
lcd c:\
cd root/output_folder
get -transfer=binary "%1%"
exit
Commands on command-line
You can also inline the commands the to the batch file:
#echo off
:retry
winscp.com /command ^
"open ftp://username:password#10.100.16.111/" ^
"lcd c:\" ^
"cd root/output_folder" ^
"get -transfer=binary ""%~1""" ^
"exit"
if not exist "%~1" timeout /t 300 & goto :retry
echo file has downloaded
pause
References:
Automating file transfers to FTP server;
Upload to multiple servers / Parametrized script.
Had you ever need to upgrade to the FTPS or the SFTP, just modify the session URL in the open command command accordingly.
(I'm the author of WinSCP)
My batch file contains a START command that runs a short vbscript program. When the batch file completes, the code of the vbscript program is shown in an open Wordpad window. This only started happening after we converted to Windows 7. Never happened under XP. Why does this happen and how can I prevent it? I have done extensive internet searching and come up with nothing.
Here is batch file:
#echo off
cls
echo.
echo Copying Latest Version of FREDS Database ...
echo.
xcopy "\\sstore02\S-Drive.OOD\OPI\FREDS\FREDS.mdb" "K:\FREDS\" /i /q /y
echo.
echo If you see "1 File(s) copied" then the copy was successful
echo.
echo Copying Shortcut Installer ...
echo.
xcopy "\\sstore02\S-Drive.OOD\OPI\FREDS\FREDS-Shortcut.vbs" "K:\FREDS\" /i /q /y
echo.
echo If you see "1 File(s) copied" then the copy was successful
echo.
echo Adding Shortcut icon to Desktop ...
echo.
Start K:\FREDS\FREDS-Shortcut.vbs
echo.
pause
You need to call cscript instat of start.
cscript /nologo K:\FREDS\FREDS-Shortcut.vbs
The option /noscript hides the version of cscript in the output.
Notepad is the registered program for the VBS extension on your machine.
Right click a VBS file and select Open With and then navigate to cscript.exe in c:\windows\system32 folder usually. Select the checkbox to always use that program and then the start command will work with VBS scripts and Cscript.
I have created a batch file which is supposed to keep track of the opened PDF files on my system.As soon as someone opens the PDF file,the name of the file as well as time of access is recorded in a log file.
Here is code of my batch file:
#echo off
echo FILE ACCESSED %1 >> I:\Batch\log.txt
echo TIME OF ACCESS %TIME% >> I:\Batch\log.txt
"C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe" %1
EXIT
I have also set up this batch file as the default application fr the PDF files to open with.
Now,the problem is,as soon as I open any PDF file,many cmd windows start opening and closing unendingly. Please suggest some remedy.
Thanks....
#echo off
copy %1 %1.tmp
echo FILE ACCESSED %1 >> I:\Batch\log.txt
echo TIME OF ACCESS %TIME% >> I:\Batch\log.txt
"C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe" %1.tmp
del %1.tmp
EXIT