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/
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 appreciate your time so I won't take much of it. Here's what I'm trying to do: I want to create a .bat file that, when executed, will open the Command Prompt program, change directory to a folder (located on the C:), then execute a line of code that will change the file permission status of all files in that folder to Everyone. I intend to create a Windows task that will run this .bat file everyday. I understand how to setup the Windows task, but I can't figure out exactly how the .bat file should be written. Can anyone help?
Here's what I've got so far:
ECHO OFF
[Tab]Start "" C:\Windows\system32\cmd.exe
ECHO OFF
[Tab]Prompt cd cd:\google drive
ECHO OFF
[Tab]Prompt cacls *.* /t /e /g everyone:f
If you're interested, here's why I'm trying to create this .bat file:
I use a single Google Drive account on two file server computers, one in each of two offices. Each office has this file server and about 10 client computers. The client computers access files on the shared Google Drive folder (located on the file server) and occasionally add/edit/delete files. Google Drive does a great job of keeping all files synced between the two offices, but one problem I have is that if office A adds a file, the only computer in office B that can see it is the file server. I have to change the file permission to "Everyone" using the file server in office B before any of the client computers in office B can see the file. Over time, it's become very annoying to manually change the file permission every day and I'm looking for a shortcut. Please let me know if you can think of a better one.
If you got the commands right then this is a batch script with them.
The && will run the following command only if the cd command was successful.
#echo off
cd /d "c:\google drive" && cacls *.* /t /e /g everyone:f
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.