I want to check existence of file on ftp server using batch script.
Right now I have this code which saves it to ftp server:
#echo off
echo user prayagimages> d:\Images\ftpcmd1.dat
echo Pass123#>> d:\Images\ftpcmd1.dat
echo put d:\Images\%~1>> d:\Images\ftpcmd1.dat
echo quit>> d:\Images\ftpcmd1.dat
ftp -n -s:d:\Images\ftpcmd1.dat 118.139.173.227
del d:\Images\ftpcmd1.dat
Lets say if I post image.jpeg to server.
How do I check whether it is on the server or not?
Thanks.
This questions seem to request similar things:
To search for a file at FTP
Windows XP Batch- IF EXIST FTP with Date Variable
Mainly the first one, but the second link has some useful info too.
Related
I want to create a batch file in Windows Server, including the following functions:
Connection to a FTP server
Copying the files from there (directory called "out") to a local directory
if success, then deleting the files from the FTP server
repeating those steps every 15 minutes
I haven't done that much with batch files so far, so it would be great if you could help me. I know there is the ftp command, and I know how to connect (ftp open), but unfortunately I don't know how to copy those files from there every 15 minutes.
Thanks a lot for your help!
To program ftp from a batch file, see http://support.microsoft.com/kb/96269. You need to call ftp like this
ftp -i -s:ftpcommands.txt
where ftpcommands.txt looks something like this:
open ftp.myftpsite.com
username
password
bin
cd out
mget *
del *
bye
For running this every 15 minutes, see other replies (at or Command Scheduler).
(The -i parameter is to turn off interactive prompting - the other way to do this is to add a prompt off command to the commands text file before the mget. Without this, mget will stop and ask you to confirm before getting each file. [Thanks to Adriano for pointing this out!])
The accepted answer by #AAT suggests using Windows built-in ftp.exe command-line client. While that can work, more often it won't, because this client does support FTP active mode only, which does not play nicely with today's ubiquitous firewalls and NATs. It also does not support encrypted FTPS (FTP over TLS/SSL).
If you have a problem with the above, you need to use a 3rd party FTP client. Most of them do support both the passive mode and encryption.
For example with WinSCP FTP client, you can use the following batch file (.bat):
WinSCP.com /command ^
"open ftp://username:password#ftp.example.com/" ^
"get /out/* c:\local\path\" ^
"exit"
In case you already have an ftp.exe script, there's a guide for converting it to WinSCP script.
For the scheduling part, see the guide to scheduling transfers to FTP server.
(I'm the author of WinSCP)
Windows has the at utility as well as the Windows task scheduler. Either one can run your program at a specified interval.
Using only one (1) .bat file script. Create the FTP script in a temporary file, run it, then delete the temporary file.
SET "FTPFILE=%TEMP%\myftpscript_%RANDOM%.txt"
ECHO>>"%FTPFILE%" open ftp.myftpsite.com
ECHO>>"%FTPFILE%" username
ECHO>>"%FTPFILE%" password
ECHO>>"%FTPFILE%" bin
ECHO>>"%FTPFILE%" cd out
ECHO>>"%FTPFILE%" mget *
ECHO>>"%FTPFILE%" del *
ECHO>>"%FTPFILE%" bye
ftp -i -s:"%FTPFILE%"
IF EXIST "%FTPFILE%" (DEL "%FTPFILE%")
EXIT /B 0
Is there a way to remotely view local administrator accounts on remote computers within a network or possibly run NET LOCALGROUP ADMINISTRATORS and have the result be viewed on the command prompt instead of extracting it in a notepad (via psexec)?
Thanks in advance!
Try a Bat file with this.
for /f %%A in (computers.txt) do (echo Identifying group members on "%%A" ...
psexec -s \%%A net localgroup administrators )
Create a txt file with computer names without spaces one name for each line.
Redirect the command to a txt file and creat a log with it.
Ex. batfile > log.txt
I'm trying to load flat file into server through FTP using batch files. I'm aware of the scripts and I'm able to transfer the file to server. Currently I'm following this below method.
#echo off
title File Transfer
color 3F
cd "C:\Users\username\Desktop\Access\"
echo -
echo - Transferring File to Server. Please be patient...
echo -
echo - Closing this window will Terminate the entire process
ftp -n -s:"C:\Users\username\Desktop\Access\ftp.txt" server_name >"C:\Users\username\Desktop\Access\ftp.log"
Script File Code: (ftp.txt)
User Userid password
mkdir App
put "C:\Users\username\Desktop\Access\File.txt" "App/File.txt"
quit
My requirement is that I should not display username and password on the script file. These credential information dynamically coming from the variables and I'm generating this batch file and script file dynamically.
Kindly any experts suggest me solution which makes more sense to accomplish this requirement. Thanks in advance.
You generally cannot encrypt anything while still allowing it to be decrypted automatically.
See for example BASH: allow users to FTP files to my server without revealing FTP login credentials to them
All you can typically do is to obfuscate the credentials. But the Windows ftp.exe does not allow even that.
With ftp.exe, you can use input redirection to somewhat reduce the risk:
(
echo user %USERNAME% %PASSWORD%
echo mkdir ...
echo put ...
echo quit
) | ftp.exe -n example.com
I need to check a file status (existing? or last modified date) on multiple remote Windows servers (in LAN). The files are accessible via UNC path. The remote PCs need a user name and password. It's best to be some sort of script.
I am not system admin, but asked to do this by my boss because each of these PCs are host of SQL Server and the file is a backup of database. I am a SQL Server database developer. I was trying to do it using T-SQL, but just found it not geared to do this (although maybe doable).
Create a batch file like (say check.bat):
#echo off
set list=server1 server2 server3 server4 serverN
for %%s in (%list%) do (
echo Logging in to %%s
net use \\%%s\shared /user:mydomain\myuser password
echo Checking file existence on %%s
if exist \\%%s\shared\file.txt (
echo File exist on %%s
) else (
echo File does NOT exist on %%s
)
echo Logging out
net use \\%%s\shared /delete
)
For details on the net use commands, see the accepted answer for question Mapping a network drive without hardcoding a drive letter in a batch file.
I am working on a project where need to upload file to FTP using sql server. I know it can be done easily by SSIS or something like that but I have some barriers there. I was thinking of using Filezilla.But I don't know how to use it through command line. So that using xp_cmdShell.
Filezilla seems a bit of an odd route to go. You can use a dos batch file and one either the built-in ftp command-line executable or another open-source/free command-line alternative.
Bare in mind that xp_cmdShell requires elevated privileges and some system parameters to be modified which generally are not recommended.
As a workaround in the past I have created a sql job which used cmdExec and then just initiate using a stored procedure.
EDIT: Added first result from google for batch file to upload to ftp
#echo off
echo user MyUserName> ftpcmd.dat
echo MyPassword>> ftpcmd.dat
echo bin>> ftpcmd.dat
echo put %1>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat SERVERNAME.COM
del ftpcmd.dat
http://www.howtogeek.com/howto/windows/how-to-automate-ftp-uploads-from-the-windows-command-line/