How to execute a batch file containing ftp commands??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to execute a batch file containing ftp commands??
# 1  
Old 10-17-2013
How to execute a batch file containing ftp commands??

hi,

is there a way i can execute a batch file containing ftp commands like we execute sftp batch file.

Code:
sftp -b batchfile user@server > output

how to create a batch file for ftp executing command and how to run the batch file from a shell script?
# 2  
Old 10-17-2013
Just asking, why would you prefer ftp while sftp provides more functionality?

As afaik ftp doesnt support 'batchfile processing', on linux at least.
In which case i'd use:
Code:
ftp user@domain > output << EOF
ls
bye
EOF

Hope this helps

Last edited by sea; 10-17-2013 at 10:57 AM.. Reason: NOTE redirection might not work, lack of experience/need.
# 3  
Old 10-17-2013
I will agree with sea that sftp would be better, but I assume that the target doesn't support it.

Could I suggest that you change the code to this to ensure that the credentials are not displayed for anyone to see with a ps -ef | grep ftp:-
Code:
ftp -nv $targethost << EOFTP >$logfile.$$
user $userid $password
cd $targetdirectory
get or put command here
quit
EOFTP

Long running FTP jobs can give far too much away to a curious user. We have our set so that every transfer has it's own set of credentials and target directory. That way if we need to change a password, then only one transfer is affected. It's a pain to stick to, but the impact of a required change makes it worthwhile.

Using $logfile.$$ also allows you to keep a history of FTP attempts in case you are re-running or have many processes that use the same basic script. You can read the log file looking for errors or success as required. make sure that you have a process to tidy them away later on.



Robin
Liverpool/Blackburn
UK
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Sftp batch file not able to execute

I have a windows batch file to connect from Server A (Windows) to Server B (UNIX) via sftp to get a file. The script is as below: sftpg3 -oStrictHostKeyChecking=no -oIdentityFile=EAPIINSTADM_hostnameA ftpeapsg@hostnameB lcd D:\APPBASE\EAPSG\GEMSSG get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG exit... (5 Replies)
Discussion started by: userguy
5 Replies

2. UNIX for Dummies Questions & Answers

FTP batch file suddenly stopped working

Hello, we have a UNIX system the runs our business data. We have 4 users that use a particular batch command file to extract data for use in the Windows side of the fence: (despreg.bat) ftp ftp> open danapak (database name) connected to danapak ftp> user ccsb password ccsb ftp>... (29 Replies)
Discussion started by: Mick_Dundee
29 Replies

3. Shell Programming and Scripting

Shell: How to execute commands from another file?

I made a configuration file for my shell script in that all the values that the shell scipt needs, are defined, but I don't know how to let the shell script use those defined variables. Thank you for your help :) (3 Replies)
Discussion started by: Alkali
3 Replies

4. Shell Programming and Scripting

Batch file for sftp commands

I am trying to automate an sftp command so that it does not stop and ask for the password each time the calling shell script #!/bin/ksh sftp -b tst_1_batchfile.txt GLAXGBUPMPSOUT@204.90.134.116 the batchfile contents : password XXXXXX cd /GLAXGBUPMPSOUT/GSKENT/GLAXGF2FOPFF put... (4 Replies)
Discussion started by: Shrabanti
4 Replies

5. Shell Programming and Scripting

How to execute commands read from another file?

Please help with this simple example. I can not figure out how to do it. A file named “job” contains only this one line:var=5I need a script to read the job file and execute it as a command. This is my attempt (it does not work):#!/bin/sh exec < job echo "var = $var"output should read “var = 5”... (5 Replies)
Discussion started by: wolfv
5 Replies

6. Windows & DOS: Issues & Discussions

Batch file to Get New Files Only through FTP

Hi there I want to create a batch file which Get (mget) the newly added Files only from specific directory on UNIX server to specific folder on windows server using FTP, and this batch file will be scheduled on the windows server to run daily to load the new files (load the newly added files... (1 Reply)
Discussion started by: alsharq
1 Replies

7. Windows & DOS: Issues & Discussions

Batch file to Get New Files Only through FTP

Hi there I want to create a batch file which Get (mget) the newly added Files only, from specific directory on UNIX server to local folder on windows server through FTP, and this batch file will be scheduled to run daily to load the new files. help me plz :confused: (1 Reply)
Discussion started by: alsharq
1 Replies

8. UNIX for Advanced & Expert Users

Execute All Commands in A contrl File

Hi , I have a situation i need to write a while loop until the end of control file.In the control file i have a 5 lines which contains commands.how can i execute all with out waiting for the first one to complete. Ex ControlFile: ScripitName Test ScriptName Test1 ScriptName Test2 ... (1 Reply)
Discussion started by: ukatru
1 Replies

9. Windows & DOS: Issues & Discussions

batch file--bunch of commands

I have a batch file that takes 2 parameters--source file location and target file location. I want to create another batch file that contains all the commands with the file locations so that I dont have to enter the ifnromation every time individually. For eg: to execute command com1.bat... (3 Replies)
Discussion started by: alfredo123
3 Replies

10. UNIX for Dummies Questions & Answers

UNIX Batch FTP Command file

Hello, I am a UNIX newbie and this is my first posting. I need to create a batch command file to ftp from Sun/Solaris to AS/400. Here is an example file: ftp -d -i -n -v 172.28.16.22 pwd ls binary quit This is the result of executing the command file: Connected to... (10 Replies)
Discussion started by: pietro
10 Replies
Login or Register to Ask a Question