MelvinProject
Posts: 6
Joined: Wed Aug 26, 2015 7:22 pm

FTP Shell script

Fri Aug 28, 2015 8:04 pm

I need to upload a file via FTP with shell script. Can I interact with FTP from the script? My Script is at http://pastebin.com/A76fsaM3

Will this work? Is there another way to interact with FTP from within a shell script? Any help is appreciated!

See http://www.tldp.org/HOWTO/FTP-3.html for information regarding interaction with FTP.

asavah
Posts: 347
Joined: Thu Aug 14, 2014 12:49 am

Re: FTP Shell script

Fri Aug 28, 2015 8:35 pm

No, bash won't work like this.

Research about "expect" (it's a special language), or you could write a python script too.

MelvinProject
Posts: 6
Joined: Wed Aug 26, 2015 7:22 pm

Re: FTP Shell script

Fri Aug 28, 2015 9:13 pm

asavah wrote:No, bash won't work like this.

Research about "expect" (it's a special language), or you could write a python script too.
StackOverflow has said otherwise.

cd MyLocalUploadDir
ftp <<EOF
open ftp.server.com
myusername
mypassword
put LocalIteam.TXT
quit
EOF

Thanks for your input. :)

java
Posts: 226
Joined: Mon Jul 21, 2014 9:41 am

Re: FTP Shell script

Sat Aug 29, 2015 7:53 am

Used to do this yonks ago with ncftp and lftp ...

User avatar
DougieLawson
Posts: 34166
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: FTP Shell script

Sat Aug 29, 2015 9:24 am

The puzzling part is why anyone would use FTP.

If you set up passwordless SSH then scp (or sftp) works without needing any funky scripting.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
rpdom
Posts: 12938
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: FTP Shell script

Sat Aug 29, 2015 12:29 pm

DougieLawson wrote:The puzzling part is why anyone would use FTP.
There are lots of reasons you might want, or need, to use ftp. For example when it's the only service available.

I still use it occasionally.

User avatar
jojopi
Posts: 3042
Joined: Tue Oct 11, 2011 8:38 pm

Re: FTP Shell script

Sat Aug 29, 2015 10:48 pm

MelvinProject wrote:StackOverflow has said otherwise.
Then you rather wasted people's time asking the question simultaneously in two places, without disclosing that.

There is not really a disagreement because a here document, like any redirection, requires you to specify exactly which lines of input go to which program. It is not like typing your script interactively.

The redirection into ftp does not allow for any error checking. Unlike using expect, you cannot be sure if the upload has succeeded.

Anyway, the best tools for automated transfers using FTP or HTTP, are the likes of curl and wget.

Code: Select all

curl --upload-file LocalIteam.TXT ftp://myusername:[email protected]/

Return to “General discussion”