Scripting FTP in linux

Alan

Fledgling Freddie
Joined
Aug 3, 2004
Messages
3,972
Help !! <bangs head against wall> I just cant find anything that works for this.

My website is hosted by a company over in the USA and I'd love to get my linux box at home to log in once a week and pull down the latest backup.tar.gz

However my login to the FTP server has an @ symbol in the name which i think is screwing things up, eg.

File : Info
Code:
ftp@mydomain.com
mypassword
cd ~/backup
get backup.tar.gz

File : fetch.sh
Code:
ftp ftp.mydomain.com < info


Just returns an error :-

AUTH not understood
AUTH not understood
KERBEROS_V4 rejected as an authentication type
Password:Name (ftp.mydomain.com:root):
 

The-Don

Loyal Freddie
Joined
Dec 11, 2003
Messages
84
Hi there, I think the issues you are having may well be cured by using the -n switch... (Restrains ftp from attempting ``auto-login'')

A script I've been playing with...

hostname='mirror.ac.uk'
username='anonymous'
password='anonymous'
filename='backup.tar.gz'

ftp -n $hostname <<ftpscript
quote USER $username
quote PASS $password
get $filename
quit
ftpscript

There are other ways of doing it... google ckermit and .netrc :)
 

Alan

Fledgling Freddie
Joined
Aug 3, 2004
Messages
3,972
ahh yeah working now, thank you :)
 

anattic

Fledgling Freddie
Joined
Dec 22, 2003
Messages
182
A couple of other apps you might consider, especially if you're trying to embed this into another script:

The straightforward wget: http://www.gnu.org/software/wget/
The alarmingly versatile cURL: http://curl.haxx.se/

Wget, for example, gets the whole thing onto one line, using URI syntax:
Code:
wget ftp://username:password@host.domain.tld/dir/file.ext
 

Alan

Fledgling Freddie
Joined
Aug 3, 2004
Messages
3,972
Yeah my preference was for WGET but as my login name has an @ in it was confusing it with the domain
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,801
hmm you may have been able to excape that with a '\' (backslash)
 

Athan

Resident Freddy
Joined
Dec 24, 2003
Messages
1,063
Hmmm, indeed wget gets confused, even with attempting to escape the @ in the username, as the code still sees that @ and assumes the following : is specifying a port number, which it isn't, it's trying to be the separator between username and password.

However lftp appears to be happy with the escaping, at least this happens:
lftp ftp://athan\@testing:wibble@ftp.fysh.org/foo.tar
---- Connecting to ftp.fysh.org (83.170.75.51) port 21
<--- 220 ProFTPD 1.2.10 Server (FTP Daemon) [83.170.75.51]
cd: Login failed: 530 Login incorrect.
And on the server end:
Jul 1 00:10:01 bowl proftpd[25564]: bowl.fysh.org (HOSTNAME[XXX.XXX.XXX.XXX]) - no such user 'athan@testing'

-Ath
 

Users who are viewing this thread

Top Bottom