Php Download File Via Ssh Port

Posted By admin On 20.12.19
Active2 months ago

Use this feature to connect to ftp server and upload or download files securely through secure SSH tunnel. Ftp server via secure SSH tunnel. Of the port from. PHP, MySQL and SSH Tunneling (Port Forwarding) Welcome to another exciting edition of “way-too-detailed explanations of obscure data-related topics.” I’m your host, Robert J. Moore, and today we’ll be exploring the exciting world of SSH Tunneling with MySQL and PHP.

This question already has an answer here:

  • Copy a file back to local system with ssh 9 answers

I'm using Linux (centos) machine, I already connected to the other system using ssh. Now my question is how can I copy files from one system to another system?

Suppose, in my environment, I have two system like System A and System B. I'm using System A machine and some other using System B machine.

How can I copy a file from System B to System A?And, copy a file from System A to System B?

Isaac
14.7k1 gold badge23 silver badges63 bronze badges
user3021349user3021349
4,6098 gold badges15 silver badges21 bronze badges

Php Ssh Client

marked as duplicate by Gilles, slm, jasonwryan, Anthon, BernhardDec 25 '13 at 7:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4 Answers

Syntax:

To copy a file from B to A while logged into B:

To copy a file from B to A while logged into A:

HalosGhost
3,9239 gold badges22 silver badges36 bronze badges
DopeGhotiDopeGhoti
49.8k5 gold badges64 silver badges101 bronze badges

In case if you need an alternate approach.

Install sshfs. if you use ubuntu/debian:

or, if you use centos/rhel:

Create an empty dir

'link' or 'mount' the two directories

'unlink' the dirs

For more see here, linuxjournal.com

Ruban SavvyRuban Savvy
5,1086 gold badges23 silver badges42 bronze badges
Dan GarthwaiteDan Garthwaite
4,2181 gold badge11 silver badges9 bronze badges

If you want to keep the files on both systems in sync then have a look at the rsync program:

KiffinKiffin

Not the answer you're looking for? Browse other questions tagged sshfile-copy or ask your own question.

Active4 years ago

I have a server in USA (Linux box B), and my home PC (Linux box A),and I need download a file from website C,

The issue is, it is very slow to download a file direct from A,so I need download the file when I log in B, and sftp get the file from A.

Is there any way that I can download file and use B as proxy directly through only one line command?

linjunhalidalinjunhalida

7 Answers

(Strange situation, doesn't something like the triangle inequality hold for internet routing?)

Anyway, try the following, on A, ssh into B with a -D argument,

which acts as a SOCKS5 proxy on 127.0.0.1:1080, which can be used by anything supporting SOCKS5 proxied connections. Apparently, wget can do this, by using the environment variable

Note that sometimes curl is more handy (i.e. I'm not sure if wget can do hostname lookups via SOCKS5; but this is not one of your concerns I suppose); also Firefox is able to work completely through such a SOCKS5 proxy.

Edit I've just now noticed that you're looking for a one-line solution. Well, how about

i.e. redirection the wget-fetched output to stdout, and redirecting the local output (from ssh running wget remotely) to a file.

This seems to work, the wget output is just a little confusing ('saved to -'), you can get rid of it by adding -q to the wget call.

Community
sr_sr_

Another approach could be that you normally log in into B, where you start a screen session. There you do the wget of your files - all into one directory.

And there the program can happily run; you just detach from screen, but let it run in the background.

If the downloads are finished (maybe even earlier), you can fech the data from B to A using rsync (my preference).

glglglglglgl

Inspired by another answer to another question, I suggest using proxychains-ng (which is the newer version of proxychains).

  1. Download, compile, and optionally install proxychains-ng.
  2. Create a proxychains.conf file in the current directory, or at ~/.proxychains/proxychains.conf, or at /etc/proxychains.conf.
    • Alternatively, create one file anywhere else, or with another name, and specify if through -f command-line argument, or through PROXYCHAINS_CONF_FILE environment variable.
    • There is a sample config file available. The most relevant options are at the very end.
  3. In your proxychains.conf file, add:

  4. Run ssh -D 1234 your_host_b. This will make ssh listen on port 1234 on localhost, and use your remote host as a SOCKS proxy.

    • Alternatively, run ssh -ND 1234 your_host_b instead. -N will prevent ssh from running any command on the remote server (i.e. it won't open a shell).
  5. Run: proxychains4 yourcommandhere yourparametershere. See some examples:
    • proxychains4 wget -O - http://ifconfig.co/
    • proxychains4 -q links http://ifconfig.co/
Denilson Sá MaiaDenilson Sá Maia
1,0531 gold badge9 silver badges14 bronze badges

In order to use wget with a SOCKS5 proxy from ssh, you have to install the security/dante package in order to use the SOCKS_SERVER option with the socksify utility.

Subsequently, you open an SSH connection in the background:

Linux Download File From Ssh

And use wget through a SOCKS5 proxy through socksify:

Just pipe the file to stdout on the server, and read it from stdin on your workstation.

cnstcnst
1,6302 gold badges14 silver badges38 bronze badges

You can do a ssh tunnel from box A to box B and add to the routing table in box A, that website C is reachable via tunnel to box B. You have to allow packet forwarding on the box B.

Here you can see a very good step-by-step tutorial..

Jan MarekJan Marek

You would need to create a tunnel on machine B tha would redirect the call to website C. But I'm puzzled as why this would be faster, unless your ISP as some restrictions. Epson perfection 640u driver windows 10.

Php Download File Via Ssh Ports

I don't know a oneliner, but this isn't much more complicated.

On machine A, you do (I took 11111 randomly, you can take whatever you want as long as it is > 1024, or you would need to be root)

The username on B is the one you use to connect to B. This should create a tunnel on port 11111 on machine B that redirect to port 80 (web site in HTTP use 443 for HTTPS) on machine C (I hope I did not mess the order ;) )

Then you can download the file directly from machine A via machine B. I'm assuming the file is at http://C/path/to/file so you would then use:

Huygens

Download File Via Ssh Terminal

Huygens
5,5742 gold badges23 silver badges34 bronze badges

You can do this via port forwarding (ssh tunneling). Here's a resource:http://www.jfranken.de/homepages/johannes/vortraege/ssh2_inhalt.en.html#ToC9

Essentially, you should set up port forwarding on B. When A issues wget to B, B will forward the packets to C and send the results back to A.

RonERonE

Not the answer you're looking for? Browse other questions tagged sshwget or ask your own question.