Access files using PHP and secured FTP - php

I need any site or book which teaches how to use ftp to access remote server in php.
Details of my problem:
Basically there are two servers.All user uploaded files are in server 2 but now I need to access those on my server1.
lets say my ftp details are like this:
ftp://userfiles.example.com
username: admin
password: 1234
then which php function can I use to create a connection to that server. I always accessed files like "../example/dir/example.txt", if there was no password then maybe I could do this
"ftp://example.com/dir/example.txt".

FTP and SFTP (you tagged your post with SFTP and kinda mention it in your question title) are different things. For FTP I'd recommend using PHP's built-in FTP functions. For SFTP.. there's a PHP extension that provides for it (ssh2) but, personally, I think phpseclib, a pure PHP SFTP implementation, is easier to use.
If you're using FTPS (FTP over SSL) then use the FTP extension.

Related

Is it possible deleting files from a different URL?

I'm trying to figure out how I could delete a file from a different URL.
The situation is similar to the one below.
Eg: abc.com/admin/xyz-admin updates the content of xyz.com.
The website XYZ has the folders with images, so I want to delete files from there with abc.com/admin/xyz-admin. I'm using Remote MySQL to connect the database.
Thanks!
You need to use FTP (or SFTP) or some protocol like that to log on to xyz.com and delete the files 'manually'.
See the PHP documentation on FTP.
Note that you would need an FTP server installed on xyz.com, and FTP is not a secure protocol.
You could also use WebDAV, for which there are some PHP libraries like https://sabre.io/dav/davclient/. Again, you would need a WebDAV server on xyz.com

Security for FTP connection between same servers

In PHP, I am accessing another user's files using FTP on the same server. In this case, do I need to use secure FTP or is it ok to have normal FTP as both source and destination are on same server?
Thanks.

Connect to shared folder with php

It's possible to connect to a shared folder and list, read or write files in the folder as if it were a local folder with php? I was searching but I haven't found anything that woks for me.
If you intend to access Windows-based Share with SMB protocol, use can use Icewind\SMD library.
It can't possible with only PHP, We can't access the local directory/file using PHP.
But, If you write some Thread or File Watcher task using Java(Watch service) or Python or any other supported technology and send file related events to your PHP web-service or API.
Not sure but if will think in that way...it can be possible.

To use cURL FTP does both servers need the PHP cURL library installed?

I'm trying to wrap my brain about how to do this. We need to provide some files within a directory from our servers to our clients' servers via a PHP/Web interface using FTP. I've looked at the FTP capabilities built in to PHP and some custom classes, but someone suggested cURL might be a better option. We will have the FTP login credentials in our database for the application to access. With that information can we use cURL FTP capabilities to do the transfers, knowing our server has libcurl installed, but the clients servers may not? Do both servers have to have it for the FTP function to work?
Or am I completely going about this the wrong way, and have misunderstood how to use cURL and should be looking into an FTP PHP class?
libCURL is a library; it acts as the client.
Your clients need to be running a FTP server but do not need libCURL.
Just to make it super clear, there are 2 computers involved:
Your server, the one that's supposed to provide files to the client using the FTP protocol. That server does not need to have a web server (or PHP) running. The only thing it needs is an FTP server. It also needs to have permissions configured in such a way that there is an account that can access the files through FTP.
Your client's server, the one that's supposed to retrieve files from your server using the FTP protocol. That server needs to have PHP installed, with libCurl. The software on that server needs to access your server using the FTP protocol, providing the user credentials that you configured on your box.
Hope that helps.
It sounds like what you want to do is have the client connect to your PHP script & then push a button to start an FTP transfer that sends a file from your FTP server to their FTP server. If this is the case, then all you need is cURL on your server.

SFTP listing directory

I'm trying to make a connection to a secure sftp site, however I'm not able to list the directory,however, it's possible to connect using python "expect" or php"ssh2_connect" but it gives me the following mesg: Received disconnect from xx.xx.xx.
If I use a GUI appliction like winscp I'm able to go to the sftp server and retrieve files.
I need to script it thus a cli interface is needed.
PS: just in case someone ran into this. I'm trying to connect to Avisena.com sftp server
You can do this easily with paramiko, checkout SFTP with Python

Categories