Transfer text file from 1 server to another in PHP

Tags: php asp.net
By : virepo
Source: Stackoverflow.com
Question!

I am a junior PHP developer working with a junior .asp developer.

On the .asp project he needs to get a .txt file from his server and put it into a folder within my server.

This will need to happen every 30 minutes or so, which will be done with a cron job id imagine.

So what is the best way to get a file from .asp project to my .php. Should i created a route and he submits a form to send the file to my server. Then i store it?

Thing is, this needs to be done every 30 minutes so its not like he make a front-end form and have it clicked every so often.

Can anyone give me some advise please?

By : virepo


Answers

You can use the scp command to acheive this and scheduel it in cron job

scp -i /path/to/ssh_identity_file /some/local/file.txt [email protected]:/some/remote/location

if you need to authenticate using the password try sshpass

sshpass -p "password" scp /some/local/file.txt [email protected]:/some/remote/location

In case you need to do this via a php script check this Php Library phpseclib

Hope this will help.

By : Yacine al


You can use file_get_contents() and file_put_contents();

$filedata = file_get_contents('http://example.com/any.txt');
file_put_contents('any.txt', $filedata);
By : Neel Ion


This video can help you solving your question :)
By: admin