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 855759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:07:46+00:00 2026-05-15T08:07:46+00:00

I am using a bash script (below) on a remote server (so far using

  • 0

I am using a bash script (below) on a remote server (so far using ssh to connect) to execute a python script that downloads a lot of pdf files one at a time (getting the download locations from a text file with the URL’s) in a loop.

I would like to move the files from the remote server to my local computer as they are downloaded, and then delete the file from the remote server. Is there a way that I can expand my bash script to do this? Or are there alternatives for completing this task?

 while read line; do python python_script.py -l $line; done < pdfURLs.txt

  • 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-15T08:07:46+00:00Added an answer on May 15, 2026 at 8:07 am

    [Edited to reflect the fact that the original poster can’t scp into his local computer from the server; I assume it’s behind NAT or something of the sort]

    [Edit 2: I’m keeping the current tunnel-based answer, for reference; but, since the original poster is unable to ssh back into his local machine, I’ll assume something else is blocking the tunnel. See the suggestion at the end].

    Ok, you’ll need to open up a tunnel between the server and your home computer. So, ssh from your local computer (I assume it’s Unix-based, you mentioned is a Mac, so that’s fine) into the server with this command:

    ssh -R 10022:localhost:22 your_server_address
    

    In brief, this will forward the server’s port 10022 (it’s a high (> 1024) port, so it’s likely to be available) to your local computer’s port 22 (which is where ssh usually listens). That is, once you’ve done that, if you ssh into the server’s 10022 port, you’re actually sshing into your local computer. If you want to test it, from the server, do:

    ssh -p 10022 localhost
    

    login with your local computer’s username and password, and you should see its shell prompt. If you do this test, remeber to log out, so as not to confuse yourself.

    Once you’ve opened the tunnel, keep that connection open. You may use it to run the bash command line that downloads the PDF etc, but that’s not necessary.

    Then, try the following command-line:

    while read line; do python python_script.py -l "$line"; scp -P 10022 *.pdf localhost:path/to/put/files/; rm *.pdf; done < pdfURLs.txt
    

    A few things to keep in mind:

    • This waits until scp has finished and only then will the python script downloaded the next PDF. You mentioned you effectively wanted this, not to keep the PDF files on the server for long.
    • This copies all PDF files from the current directory to your local computer (and then erases them), so preferably run this from a previously empty directory.
    • I assume you can scp without having to type a password (using shared key authentication, for instance), otherwise it might get a bit annoying, having to retype your password all the time.

    That should do it.

    [Edited to add this alternative, for when the tunnel doesn’t work]

    If that fails, I can only assume something else is blocking your ssh/scp from the server to your local machine. In that case, you may try something different: from you local machine, do

    while read line; do ssh -n server_address "cd tmp_download_directory && rm -f *.pdf && python python_script.py -l $line" && scp server_address:tmp_download_directory/*.pdf /local/path/to/put/files/; done < pdfURLs.txt; ssh server_address "rm -f tmp_download_directory/*.pdf"
    

    (The “-n” switch to ssh is necessary, not to feed subsequente $lines into the ssh shell.)

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

Sidebar

Ask A Question

Stats

  • Questions 465k
  • Answers 465k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer s/^(name,(\d+).*)/$1,$hash{$2}/; First, the parens are numbered in the order of… May 16, 2026 at 1:30 am
  • Editorial Team
    Editorial Team added an answer If you download the plugin archive that you linked, there… May 16, 2026 at 1:30 am
  • Editorial Team
    Editorial Team added an answer Have you tried using the @BatchSize annotation? @BatchSize(size = 20)… May 16, 2026 at 1:30 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.