• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using FTP to upload files

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using the bash shell on a UNIX machine and I'm in the process of writing a shell script to upload some files to another machine.

Here is a portion of my script:

ftp -n $HOST1
quote USER $USER
quote PASS $PASSWD
cd $DIR
put $FILE1 $FILE2
quit

ftp -n $HOST2
quote USER $USER
quote PASS $PASSWD
cd $DIR
put $FILE1 $FILE2
quit
END_SCRIPT

When I upload my files how would I check that they were uploaded completely? If I get an error during an upload, how would I specify that there should be a retry?

Is this line correct? put $FILE1 $FILE2

Is it correct to quit one FTP connection before trying to make another FTP connection?

 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rather than a straight shell script to do the upload, you might want to look at "expect" and see if it will work for you. It's designed for that sort of task. You'll probably have to get samples of both "upload succeeded" and "upload failed" messages from that particular server so that you'll known what to, er, expect.

You CAN terminate the ftp client program in between file uploads, but there's a fair amount of overhead/delay each time you disconnect and reconnect, so I'd try and do it all in one go, myself.

In the event of switching from one FTP host to another, the overhead is going to be there regardless, so whether you run the FTP client twice or simply once with a disconnect from the first host followed by a connect to the second is mostly a matter of taste. Running each connection on a separate instance of the client program does, however mean that you can fork them and run the two sessions concurrently instead of having the second connection wait on the first one.
 
Alissa Horner
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Rather than a straight shell script to do the upload, you might want to look at "expect" and see if it will work for you. It's designed for that sort of task. You'll probably have to get samples of both "upload succeeded" and "upload failed" messages from that particular server so that you'll known what to, er, expect.

You CAN terminate the ftp client program in between file uploads, but there's a fair amount of overhead/delay each time you disconnect and reconnect, so I'd try and do it all in one go, myself.

In the event of switching from one FTP host to another, the overhead is going to be there regardless, so whether you run the FTP client twice or simply once with a disconnect from the first host followed by a connect to the second is mostly a matter of taste. Running each connection on a separate instance of the client program does, however mean that you can fork them and run the two sessions concurrently instead of having the second connection wait on the first one.



Thank you for letting me know about "expect."

I have another question. Here is a portion of my script. When the script below executes, I'm getting a message saying that I'm already logged in. $HOST1 and $HOST2 are different URLs. How can I avoid this error?

ftp -inv $HOST1 <<EOF
quote USER $USER
quote PASS $PASSWD
cd $DIR


ftp -inv $HOST2
quote USER $USER
quote PASS $PASSWD
cd $DIR
bye
EOF

If I were to execute the following script, the script only allows me to log on to the $HOST1, but not $HOST2. Any reason why?

ftp -inv $HOST1 ><<EOF
quote USER $USER
quote PASS $PASSWD
cd $DIR
bye

ftp -inv $HOST2
quote USER $USER
quote PASS $PASSWD
cd $DIR
bye


EOF
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic