Avatar of Theorem44
Theorem44 asked on

Transfering a file to anothe UNIX server using SFTP

I have a PHP Script that generates a CSV file on an hourly basis. This file is stored in a secure directory on the server.

I need to transfer this file after it is generated to a third party server via SFTP connection.

I need to do this with a PHP script.

Any Ideas?
PHP

Avatar of undefined
Last Comment
glcummins

8/22/2022 - Mon
glcummins

You can open an SFTP connection using the function ftp_ssl_connect(). For complete information, the manual page is here:

 http://us3.php.net/ftp_ssl_connect
ASKER
Theorem44

I will give it a try.

Isn't an SSL-FTP connection different from a SFTP connection though?
yaronj

KISS
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
yaronj

SFTP is not FTPS.
FTPS is ftp over ssl and uses port 21 while SFTP uses another port (I think 990)
glcummins

You may wish to take a look at this comment from the fopen() manual page:

 http://us3.php.net/manual/en/function.fopen.php#51987

Apparently SFTP is possible after installing the libssh2 library and PECL SSH2 module.

Another alternative is to examine why you need to use SFTP in the first place. If you are primarily trying to gain the encryption protection, you can encrypt your data programmatically before opening a connection using one of the standard transfer methods.
ASKER
Theorem44

Some things have changed since I started toying with the deal.

The client's site is now on its own Unix server, so I have full access to all aspects.

Thinking through the problem a little more, I think there might be another way to go.

Does anybody know of a way to write an automated script to simply use UNIX sftp to sync the folder once a day?

Could a simple CRON job be used to Simply sync a folder? Then I could use an additional CRON to have PHP delete the old files and add an updated one each evening.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
glcummins

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question