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

  • SEARCH
  • Home
  • 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 6147975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:11:53+00:00 2026-05-23T19:11:53+00:00

I have a FTP URL, and have to parse the URL to get the

  • 0

I have a FTP URL, and have to parse the URL to get the username, password, server name and the directory. What can be the regular exp to do it?

ex: ftp://userName:password@someServer/direcory-name

  • 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-05-23T19:11:54+00:00Added an answer on May 23, 2026 at 7:11 pm

    Whenever I think of regexes, I think “Perl” and write a quick and dirty pattern (qr{xxx}x) and test it against test input.

    In your case, assuming that user name, password, server, and directory name all need to be parsed out (and are mandatory), I’d use the following. Add question marks for “optional” parts of your pattern if you wish to modify this:

    qr{
        ^           # Start of text
        ftp:        # Protocol
        //          # Double slash
        ([^:]+)     # $1 = User Name
        :           # Colon
        ([^@]+)     # $2 = Password
        @           # AT sign
        (.*?)       # $3 = Server name
        /           # Single slash
        (.*?)       # $4 = Directory name
        (\?.*)?     # Question mark ends URI
        $           # End of text
    }x;
    

    Now that we have the pattern, simply double the backslash (in the “Question mark” portion), remove spaces and comments (if you wish), and place into a Java String:

    "^ftp://([^:]+):([^@]+)@(.*?)/(.*?)(\\?.*)?$";
    

    Use that with Pattern/Matcher and you should be able to extract things nicely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a directory listing of files on an ftp server using
I have a FTP server which I use for Linux repository for RPM packages.
We have several cron jobs that ftp proxy logs to a centralized server. These
I have to upload a file to an FTP server. The filename contains special
I have crated a ftp server and placed my website code over there. Now
Im trying to check if a directory exists on an FTP server. Before you
I have a series of files on a private ftp file server that I
I created a function to download files from an FTP server that I have
I have an ftp://host/path URL and want to download the file and resume download
I have manually uploaded a file to a FTP server. When trying to access

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.