Operating System - Linux
1819866 Members
2631 Online
109607 Solutions
New Discussion юеВ

How to script ftp file transfer from Linux to Linux server

 
SOLVED
Go to solution
Debbie Fleith
Regular Advisor

How to script ftp file transfer from Linux to Linux server

I need to automate the transfer of a bunch of files from one directory from a Linux server to another Linux server.

I'm familair with initiating an automated ftp script from an NT server platform, i.e. "ftp -i -s:path/script_name" and I know what's required in the script.

However, how would I initiate an automated ftp session from Linux?

Is there a better way to automate the transfer of files from Linux to Linux?

I'm just looking for a short-term simple solution here.
10 REPLIES 10
Ivan Ferreira
Honored Contributor

Re: How to script ftp file transfer from Linux to Linux server

To copy files from server to server in Linux you have several options:

Use rsync.
Use scp.
Use ftp.

Read the following documents and choose your preferred method:

www.networkeval.com/downloads/PrivatePublicKeySetup.pdf
http://www-128.ibm.com/developerworks/linux/library/l-backup/?ca=dgr-lnxw41Backup
http://www.jdmz.net/ssh/
http://www.mcwalter.org/technology/shell/ftp.html
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Debbie Fleith
Regular Advisor

Re: How to script ftp file transfer from Linux to Linux server

I was able to find other automated ftp forum topics on the HP-UX side and have come up with this solution that worked fine:

ftp -n << ENDFTP
user
prompt
ascii
lcd
cd
mget *
ENDFTP
Manuel Wolfshant
Trusted Contributor
Solution

Re: How to script ftp file transfer from Linux to Linux server

Even you have already solved your problem, I suggest taking a look at lftp (http://lftp.yar.ru/ ). It's the best CLI ftp client I have seen in 15 years. You can script it using via external files, schedule it, pipe files to other applications, apply bandwidth limits and a lot more.

A short tutorial is available at http://www2.papamike.ca:8082/tutorials/pub/lftp.html
Atul Gautam
Valued Contributor

Re: How to script ftp file transfer from Linux to Linux server

Hi Debbie,

You can configure "SSH" first of all.

Then, the best way to automate this task is by writing a "SCRIPT" and schedule its execution using the "CRON" facility.

Whatever Manuel has specified, you can do the same thing while using the "scp" command, all you need to do is to go through its "man" page.




Atul
Thomas J. Harrold
Trusted Contributor

Re: How to script ftp file transfer from Linux to Linux server

If this is a regular, scheduled FTP, with information that may or may not change, I'd recommend rsync instead of FTP, as you'll only copy bytes that have changed.

If it's new data every time you initiate the FTP, it doesn't much matter which method you choose.

(although rsync can use ssh as a transport, which is much more secure)

Lastly, see if you can modify your ftp script to use sftp instead...

-tjh
I learn something new everyday. (usually because I break something new everyday)
Alan_152
Honored Contributor

Re: How to script ftp file transfer from Linux to Linux server

A short tutorial on scripting ftp under *nix: http://www.inlumineconsulting.com:8080/website/scripting.ftp.html
vnykr
Advisor

Re: How to script ftp file transfer from Linux to Linux server

u may use secured ftp(sftp)
$sftp userid@hostname
u will asked for passwd
after that
use following commands ..
*********************************
(1)inorder to get a file from ur account to ur local system use "mget" as follows
mget [filename]
or
get [filename]
(2)inorder to put file from ur local system to ur account use "mput" as follows
mput [filename]
or
put [filename]
**************************************
some other cmds that r useful is
***************************************
cd //Change the directory on the remote computer
chmod //Change the permissions of files on the remote computer
chown //Change the owner of files on the remote computer
dir (or ls) // List the files in the current directory on the remote computer
help (or ?) //Get help on the use of SFTP commands
lcd //Change the directory on the local computer
lls //See a list of the files in the current directory on the local computer
lmkdir //Create a directory on the local computer
ln (or symlink)//Create a symbolic link for a file on the remote computer
lpwd //Show the current directory (present working directory) on the local computer
lumask //Change the local umask value
mkdir //Create a directory on the remote computer
pwd //Show the current directory (present working directory) on the remote computer
rename //Rename a file on the remote host
rm //Delete files from the remote computer
rmdir //Remove a directory on the remote host (the directory usually has to be empty)
version //Display the SFTP version
! //In Unix, exit to the shell prompt, where you can enter commands. Enter exit to get back to SFTP. If you follow ! with a command (e.g., !pwd), SFTP will execute the command without dropping you to the Unix prompt

bye
vnykr
Mark Wolf_2
Advisor

Re: How to script ftp file transfer from Linux to Linux server

Take your pick on the solutions mentioned above. I had a similar issue to resolve a while back. I had a short window and a great deal of data to move. I started out using scp. Scp was to slow it was taking hours to move the data. I tried sftp and found it to be even slower that scp. I have found rsync to be faster in almost every case.

If speed is an issue, I would use rsync.

Mark
Steven E. Protter
Exalted Contributor

Re: How to script ftp file transfer from Linux to Linux server

Shalom,

http://www.hpuxconsulting.com/5004.ppt

Developed but never delivered to HP World 2005.



SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
kabucek
Advisor

Re: How to script ftp file transfer from Linux to Linux server

@echo off


set /P my_folder="Please enter folder to zip and FTP: "

if exist %my_folder% goto do_zfile
goto error

:do_zfile

cd %my_folder%

rem .: if your date has '/' in the date, they need to be stripped out.
for /f "delims='/'" %%i in ('%date%') do
set my_date=%%i-%%j-%%k
winzip32 -min -a -p -ex -hs *.* %my_date%.zip

set /P my_loc="Please enter FTP site: "
set /P my_id="Please enter your ID: "
set /P my_pass="Please enter your Password: "

echo open %my_loc% > ftp_conn.txt
echo user %my_id% %my_pass%>> ftp_conn.txt
echo binary >> ftp_conn.txt
echo hash >> ftp_conn.txt
echo put %my_date%.zip >> ftp_conn.txt
echo close >> ftp_conn.txt
echo quit >> ftp_conn.txt

ftp -s:ftp_conn.txt

del ftp_conn.txt
del %my_date%.zip

goto done

:error
echo Folder was not found.

:done





- This is my batch file for ftp program. I want uses that file with SmartFTP. And when I launch that file it asking me for a file├в ┬ж I├в m typing C:\test\ - and it├в s says that, the syntax of the command is incorrect. Why??? What is the correct command???