This question already has an answer here:
How can I use bat file to achieve ftp function without txt file? or the password can be encrypted in txt file?
(1 answer)
Closed 11 months ago.
I am unable to find a way to have a batch file login to a FTP server without a different file being needed. The script is being run remotely on customer computers through Atera so we can grab customer bitlocker encryption keys then send a file that was created from the same script containing the keys. I would love some help for this on how to automatically login with the FTP username and password.
:: #echo off
set CUR_YYYY=%date:~10,4%
set CUR_MM=%date:~4,2%
set CUR_DD=%date:~7,2%
set SUBFILENAME=%CUR_YYYY%%CUR_MM%%CUR_DD%-%CUR_HH%%CUR_NN%%CUR_SS%
::Might move the computer name into variable SUBFILENAME
echo
cd..
cd..
manage-bde -protectors c: -get > c:\BLK\BLK_%computername%_%SUBFILENAME%.txt
My computer has PURE-FTPd for the client.
If I were to manually use the FTP to send a file the command prompt would look like this but will not work in the batch file due to it not reading the username and password
C:\>ftp website.com
Connected to website.com.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 2 of 500 allowed.
220-Local time is now 13:59. Server port: 00.
220-This is a private system - No anonymous login
220 You will be disconnected after 15 minutes of inactivity.
504 Unknown command
User (website.com:(none)): USERNAME
331 User person#website.com OK. Password required
Password:PASSWORD
230-Your bandwidth usage is restricted
230 OK. Current restricted directory is /
ftp> cd Test
250 OK. Current directory is /Test
ftp> put C:\BLK\Ethan.txt
200 PORT command successful
150 Connecting to port 60060
226 File successfully transferred
The password is hidden while typing it
The standard FTP command-line client with Windows requires a response file (option -s:file) to work properly in batch mode. Otherwise, it works in interactive mode, and you'll need a separate process to pilot it through its stdin/stdout if you want an automatic operation.
Otherwise, you can use psftp, shipped with PuTTY.
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
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 am creating a batch file to open a RDP session.
The remote desktop uses a gateway, so there are 2 credentials to be entered.
One for the gateway and other for the remote desktop.
I have written the following code:-
cmdkey /generic:gateway/abc.com /user:user1 /pass:password1
cmdkey /generic:TREMSRV/10.2.13.4 /user:user2 /pass:password2
start mstsc /v:10.2.13.4
But on running this code the pop to enter first set of credentials appears. I want to hardcode the credentials in the batch file itself
Can anyone suggest how shall i accomplish this ?
We have a file that we send to the bank and it worked via bat file when sending through FTPS.exe but not we must use PSFTP.exe which works for the desktop user but not the service account. We have tried logging in as the service account user and running the process which works when we are logged in as but not when scheduled through a Windows Server. Have also tried putting the Y in the bat file to answer the validate question whcih we have to answer only once when using desktop user without success.
I have read a lot of hits online pointing to authentication, using two files, etc... but not sure how to implement them. I would really appreciate assistance with this.
here is my bat file which is called by Gentran as an executeable, server is Windows 2008 R2, Service Pack1:
SET MOVEitIP=FTX-SERVSH.bnymellon.com
SET MOVEitUser=******
SET MOVEitPassword=******
echo cd /inbound/trp/ >> frommoveit.txt
echo mput D:\GENSRVNT\PositivePay\*.txt >> frommoveit.txt
echo quit >> frommoveit.txt
psftp -batch %MOVEitIP% -l %MOVEitUser% -pw %MOVEitPassword% -b frommoveit.txt
del frommoveit.txt
Basically took script from bat file for FTPS.exe and updated it for PSFTP.exe to use. Again, this works as desktop user and service account user (when signed into the server) but not when automated.
Thank you in advance for your assistance.
Krise
The service account must have the "Log On Locally" rights otherwise the account will not be able to logon to execute the sheduled task. I think you will see the logon error in the eventvwr at the time the task was run.
I need to make a batch file which opens my ftp server automatically,How do i automatically input user name and password to the ftp username and password prompt.I have tried to use
echo username|ftp ipadress,but it is taking the input for both user name and password. So I need help to create a batch file, which automatically logins as "user" and password "pass"
Before you use the following script, please remember that the FTP protocol
doesn't allow encryptions, the authentication process and the data transitions.
Create a new text file with the following text:
open "myservername/serverip"
"%username%"
"password"
cd /upload
bin
hash
put/get "filename.cab"
bye
Note: Please choose the correct ftp commands to allow the script to work.
Save the file as runftp.txt (For example).
Run the command: c:\windows\system32\ftp.exe -s:runftp.txt
SOURCE: http://support.microsoft.com/kb/555976