3

I need to create a bash script which will connect to an FTP server, upload a file and close the connection. Usually this would be an easy task but I need to specify some specific proxy settings which is making it difficult.

I can connect to the FTP fine using a GUI client i.e. Filezilla with the following settings:

Proxy Settings
--------------
FTP Proxy : USER@HOST
Proxy Host: proxy.domain.com
Proxy User: blank
Proxy Pass: blank

Proxy Settings

FTP Settings
------------
Host : 200.200.200.200
Port : 21
User : foo
Pass : bar

FTP Settings

What I can't seem to do is replicate these settings within a text based ftp client i.e. ftp, lftp etc. Can anyone help with setting this script up?

Thanks in advance!

1 Answers1

4

According to the docs, lftp should support the ftp_proxy environment variable, e.g.

ftp_proxy=ftp://proxy.domain.com lftp -c "cd /upload; put file" ftp://200.200.200.200

If that works, you can put

export ftp_proxy=ftp://proxy.domain.com

in your shell configuration files, or

set ftp:proxy=ftp://proxy.domain.com

in your ~/.lftprc.

Alternatively, try running the commands that your GUI FTP client is running, e.g.

upload.lftp

USER ...@...
PASS ...
PUT ...

And run it using -s:

lftp -s upload.lftp 200.200.200.200

Or try curl -T (docs) ncftpput (docs).

Something like:

FTP_PROXY=ftp://proxy.domain.com curl -T uploadfile -u foo:bar ftp://200.200.200.200/myfile

might work.

Mikel
  • 24,855
  • 8
  • 65
  • 66
  • Mikel : Tried both methods without any luck they just time out. I added some screenshots hopefully then can help? –  Mar 17 '11 at 02:35
  • @schone: Ah, it looks like it's using an FTP proxy, not an HTTP proxy. Can you try using `ftp_proxy=ftp://proxy.domain.com lftp...`? – Mikel Mar 17 '11 at 03:07
  • Brillant! It works! I did the following: $ export ftp_proxy=proxy.domain.com $ lftp user:pass@200.200.200.200 :) Thanks! –  Mar 17 '11 at 03:38
  • @mikel, it should be `set ftp:proxy ftp://proxy.domain.com`, no equal sign after ftp:proxy nice trick though – kaklon Jan 11 '19 at 14:23