Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Sat Nov 18, 2017 4:27 pm


Ftp, sftp, scp, rsync and other data transfer daemons.

Author Message
nikonjd
Post  Post subject: How to use ftpproxy in a unix script  |  Posted: Fri Feb 20, 2015 1:36 pm

Joined: Fri Feb 20, 2015 1:13 pm
Posts: 3

Offline
 

How to use ftpproxy in a unix script

My apologies if this goes in twice.

We have a client who only uses ftp for file transfers. On our Unix server I can use the following at the command line and I can access the client ftp server. How can I use this in a script?

ftp ftpproxy <enter>
userid@host <enter>
password <enter>





How to use ftpproxy in a script.


Top
mandrei99
Post  Post subject: Re: How to use ftpproxy in a unix script  |  Posted: Sat Feb 21, 2015 7:15 pm

Joined: Tue Aug 04, 2009 9:16 am
Posts: 245

Offline
Hi,

Have you checked “expect” interpreter ? You can use it to automate authentication system that require human interraction.

Here’s an example to automat FTP login with this “expect”:

Expect installation under Debian Linux


Code:
$ sudo apt-get install expect
$  which expect
/usr/bin/expect

Automate FTP login with expect script


Code:
$ vim auto-ftp.sh
#!/usr/bin/expect

spawn ftp ftp.domain.com
expect -re "Name \(.*\):"
send "sombody\r"
expect "Password:"
send "password\r"
expect "ftp>”


Few notes on above ftp script:
- you need to send the linux new line feed (the ENTER) character ‘\r’ at the end of every command.
- you can further customize it to upload or download files from the ftp server automatically:
Code:
send “get 1MBfile\r”
expect "ftp>"
send "bye\r"
interact

Quoting expect documentation:
Quote:
Interact is an Expect command which gives control of the current process to the user, so that keystrokes are sent to the current process, and the stdout and stderr of the current process are returned.


Then to run the auto ftp script:
Code:
$ expect auto-ftp.sh
spawn ftp ftp.domain.com
Connected to ftp.domain.com.
220 vsftpd
Name (ftp.domain.com:root): sombody
331 Password required for sombody
Password:
230 User sombody logged in
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> get 1MBfile
local: 1MBfile remote: 1MBfile
200 PORT command successful
150 Opening BINARY mode data connection for 1MBfile (1000000 bytes)
bye
226 Transfer complete
1000000 bytes received in 12.52 secs (78.0 kB/s)
ftp> bye
221 Goodbye.


Top
nikonjd
Post  Post subject: Re: How to use ftpproxy in a unix script  |  Posted: Sat Feb 21, 2015 8:57 pm

Joined: Fri Feb 20, 2015 1:13 pm
Posts: 3

Offline
Thanks! This works as well
ftp -vn <<EOF
open ftpproxy
userid@host password
cd /wherever/the/file/is
get file
close
EOF


Top
mandrei99
Post  Post subject: Re: How to use ftpproxy in a unix script  |  Posted: Sun Feb 22, 2015 4:54 am

Joined: Tue Aug 04, 2009 9:16 am
Posts: 245

Offline
Good that it works for you. It does not for me on BSD / MAC ftp.


Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "How to use ftpproxy in a unix script"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. How to use ftpproxy in a script

nikonjd

1

289

Sat Feb 21, 2015 7:15 pm

mandrei99 View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO