Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8240599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:32:31+00:00 2026-06-07T20:32:31+00:00

I am using the Bash FTP command to ftp files, however i have a

  • 0

I am using the Bash FTP command to ftp files, however i have a problem where i try to create a directory that is more than 2 folders deep. It works if i use two folders deep but if i go to three folders deep then it fails. For example:

mkdir foo/bar - this works
mkdir foo/bar/baz - this fails

I have also tried this:

mkdir -p foo/bar/baz - which didn't work, it ended up creating a '-p' directory

The shell script i am trying to run is actually quite simple but as you can see the directory structure is 3 folders deep and it fails to create the required folders:

#!/bin/bash
DIRECTORY="foo/bar/baz"
FILE="test.pdf"         
HOST="testserver"           
USER="test"         
PASS="test"         

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASS
mkdir $DIRECTORY
cd $DIRECTORY
binary
put $FILE
quit
END_SCRIPT
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:32:32+00:00Added an answer on June 7, 2026 at 8:32 pm

    mkdir under ftp is implemented by the ftp server, not by calling /bin/mkdir no such options as -p,
    what you should do is

    mkdir foo
    cd foo
    mkdir bar
    cd bar
    mkdir baz
    cd baz
    

    If you still want your original construct, you can also do it like this:

    #!/bin/bash
    foo() {
        local r
        local a
        r="$@"
        while [[ "$r" != "$a" ]] ; do
            a=${r%%/*}
            echo "mkdir $a"
            echo "cd $a"
            r=${r#*/}
        done
    }
    DIRECTORY="foo/bar/baz"
    FILE="test.pdf"         
    HOST="testserver"           
    USER="test"         
    PASS="test"         
    
    ftp -n $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASS
    $(foo "$DIRECTORY")
    binary
    put $FILE
    quit
    END_SCRIPT
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using bash, I have a list of strings that I want to use to
How does one test for the existence of files in a directory using bash
I'm trying, using bash, to merge the content of a list of files (more
I am using bash shell on linux and want to use more than 10
The problem is simple: Using bash, I want to add a directory to my
When I create a Automator action in XCode using Bash, all files and folder
I'm using bash. Suppose I have a log file directory /var/myprogram/logs/ . Under this
I'm attempting to copy a series of files and folders using BASH in Ubuntu.
Using bash, how can one get the number of files in a folder, excluding
I wish to create a shell Menu Instead of using bash for my script,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.