How to copy and paste a folder and its contents on a vps using ftp php
I want to copy & paste a folder and its contents in my vps. my code is below :
$conn = ftp_connect("my_ip_address");
ftp_login($conn, "username", "password");
$src = "/var/www/src_folder";
$dst = "/var/www/dst_folder";
ftp_exec($conn, "cp -r $src $dst");
if(ftp_exec($conn, "cp -r $src $dst")) echo "success copy";
ftp_close($conn);
but my results is ftp_exec(): Unknown SITE command.
1 answer
-
answered 2022-05-04 11:23
Chris
You cannot copy directly via FTP - there's no valid command for it. These are the available commands.
If you must use FTP (vs. SSH for example), then I believe your best option is to download the file and then upload it to the copy destination.
For example, if you were just dealing with a single file or empty directory, you could do something like this:
$local_temp_file = sys_get_temp_dir() . '/tmpfile'; ftp_get($conn, $local_temp_file, $src_file); ftp_put($conn, $dst_file, $local_temp_file); unlink($local_temp_file);
However, since you are dealing with a folder with all its contents, that adds additional complexity - you will need to recursively transfer all folder contents in the same manner - both when downloading and when uploading.
You can put together a solution by referencing answers on these other posts:
Or, you can use a library to simplify the problem a bit - for example, https://github.com/Nicolab/php-ftp-client, which has "putAll" and "getAll" methods that will help you with directories.
do you know?
how many words do you know
See also questions close to this topic
-
How to upload a video using ACF in WordPress?
I am still at learning phase in WordPress. I cannot figure out in ACF which field type should I choose to upload a video file and which code should I write to show it at the front-end. Please look into the below code. I am using the_field('') but it isn't working. Can anyone help
<video width="954" height="535" controls class="tm-mb-40"> <source src="video/wheat-field.mp4" type="video/mp4"> Your browser does not support the video tag. </video>
-
delete a table form a database using laravel command
i need to delete a database table using laravel artisan command . not like this command php artisan migrate:rollback --step=5
i need to create like this route or controller code .
Route::get('/clear/database', function () {
Artisan::call('cache:clear'); return redirect('/');
});
. i also try public function dd()
{ Schema::drop('table_name'); }
but it not working . gives me error like this SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table
table_name
)no foreign key for the table . what should i do ?
thanks in advance!
-
Creating Sticky Navbar with Drop Down Menu HTML
I am creating a HTML web page which contains a sticky navbar with drop down menu. However, when I created one, the dropdown menu does not works in the sticky navbar and so goes vise versa. below is the screenshot of both the result of the two codes.
*image with dropdown menu but without sticky navbar
*image with sticky navbar but without dropdown menu
below is the code for "image with dropdown menu but without sticky navbar"
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font- awesome/4.7.0/css/font-awesome.min.css"> <style> body {margin:0;font-family:Arial} .topnav { overflow: hidden; background-color: #333; } .topnav a { list-style-type: none; float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; position: sticky; } .active { background-color: #04AA6D; color: white; } .topnav .icon { display: none; } .dropdown { float: left; overflow: hidden; } .dropdown .dropbtn { font-size: 17px; border: none; outline: none; color: white; padding: 14px 16px; background-color: inherit; font-family: inherit; margin: 0; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .dropdown-content a { float: none; color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .topnav a:hover, .dropdown:hover .dropbtn { background-color: #555; color: white; } .dropdown-content a:hover { background-color: #ddd; color: black; } .dropdown:hover .dropdown-content { display: block; } @media screen and (max-width: 600px) { .topnav a:not(:first-child), .dropdown .dropbtn { display: none; } .topnav a.icon { float: right; display: block; } } @media screen and (max-width: 600px) { .topnav.responsive {position: relative;} .topnav.responsive .icon { position: absolute; right: 0; top: 0; } .topnav.responsive a { float: none; display: block; text-align: left; } .topnav.responsive .dropdown {float: none;} .topnav.responsive .dropdown-content {position: relative;} .topnav.responsive .dropdown .dropbtn { display: block; width: 100%; text-align: left; } } </style> </head> <body> <div class="header"> <h2>Scroll Down</h2> <p>Scroll down to see the sticky effect.</p> </div> <div class="topnav" id="myTopnav"> <a href="#home" class="active">Home</a> <a href="#news">News</a> <a href="#contact">Contact</a> <div class="dropdown"> <button class="dropbtn">Dropdown <i class="fa fa-caret-down"></i> </button> <div class="dropdown-content"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> </div> <a href="#about">About</a> <a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a> </div> <div style="padding-left:16px"> <h2>Responsive Topnav with Dropdown</h2> <p>Resize the browser window to see how it works.</p> <p>Hover over the dropdown button to open the dropdown menu.</p> </div> <h3>Sticky Navigation Bar Example</h3> <p>The navbar will <strong>stick</strong> to the top when you reach its scroll position.</p> <p><strong>Note:</strong> Internet Explorer do not support sticky positioning and Safari requires a -webkit- prefix.</p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <script> function myFunction() { var x = document.getElementById("myTopnav"); if (x.className === "topnav") { x.className += " responsive"; } else { x.className = "topnav"; } } </script> </body> </html>
below is the code for "image with sticky navbar but without dropdown menu"
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font- awesome/4.7.0/css/font-awesome.min.css"> <style> body { font-size: 20px; } body {margin:0;} ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #333; position: -webkit-sticky; /* Safari */ position: sticky; top: 0; } li { float: left; } li a { display: block; color: white; text-align: center; padding: 16px 20px; text-decoration: none; } li a:hover { background-color: #111; } /*======================================================================*/ body { background-color:white; } ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #38444d; } li { float: left; } li a, .dropbtn { display: inline-block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; } li a:hover, .dropdown:hover .dropbtn { background-color: red; } li.dropdown { display: inline-block; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .dropdown-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .dropdown-content a:hover {background-color: #f1f1f1;} .dropdown:hover .dropdown-content { display: block; } footer { text-align: center; padding: 3px; background-color: DarkSalmon; color: white; } </style> </head> <body> <div class="header"> <h2>Scroll Down</h2> <p>Scroll down to see the sticky effect.</p> </div> <ul> <li><a href="#home">Home</a></li> <li><a href="#news">News</a></li> <li class="dropdown"> <a href="javascript:void(1)" class="dropbtn">Dropdown</a> <div class="dropdown-content"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> </li> </ul> <h3>Sticky Navigation Bar Example</h3> <p>The navbar will <strong>stick</strong> to the top when you reach its scroll position.</p> <p><strong>Note:</strong> Internet Explorer do not support sticky positioning and Safari requires a -webkit- prefix.</p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <p>Some text to enable scrolling. </p> <footer> <p>Author: Hege Refsnes<br> <a href="mailto:hege@example.com">hege@example.com</a></p> </footer> </body> </html>
Please i need some help with this as i am new to html and css.
-
Linux on Lightsail instance is asking for a password and it's not working
I'm trying to restart
mariaDB
on Ubuntu but it's not letting me.I enter:
systemctl restart mariadb
and get:
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units === Authentication is required to restart 'mariadb.service'. Authenticating as: Ubuntu (ubuntu) Password: polkit-agent-helper-1: pam_authenticate failed: Authentication failure ==== AUTHENTICATION FAILED ===
I have the same password for all functions so I do not understand why it is not working. What can I do?
-
How to tag and store files, by metadata, in Python?
I want to build a manual file tagging system like this. Given that a folder contains these files:
data/ budget.xls world_building_budget.txt a.txt b.exe hello_world.dat world_builder.spec
I want to write a tagging system where executing
py -3 tag_tool.py -filter=world -tag="World-Building Tool"
will output
These files were tagged with "World-Building Tool": data/world_building_budget.txt hello_world.dat world_builder.spec
Another example. If I execute:
py -3 tag_tool.py -filter="\.txt" -add_tag="Human Readable"
It will output
These files were tagged with "Human Readable": data/world_building_budget.txt a.txt
I am not asking "Do my homework for me". I want to know what approach I can take to build something this? What data structure should I use? How should I tag contents in a directory?
-
Installing pillow fails on Linux environment or Chrome OS. How do I fix this?
When I try to install pillow with pip3, it gives me the following error message.
failed building wheel for pillow
[omitted text]
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-092vzzoo/pillow/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-v4rw5g1c/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-092vzzoo/pillow/
-
Foreach for Categories
i have this data, I want to loop with categories for each question. Right now all I can do is loop by displaying sequentially for each question (as in the image).what I want to do is loop and group them based on categories_id , if the categories_id changes it will be given a new line.
// 20220507095412 // http://127.0.0.1:8000/user/exams [ { "id": 16, "ujians_id": 11, "questions_id": 3, "mulai": null, "berakhir": null, "durasi": 60, "isAnswer": 0, "created_at": "2022-05-07T02:53:56.000000Z", "updated_at": "2022-05-07T02:53:56.000000Z", "questions": { "id": 3, "title": "2", "question": "<p>Sarana yang sangat masih dalam menyebabkan oposisi dunia yang sering berdampak pada intervensi asing terhadap Indonesia pada era globalisasi sekarang ini adalah...</p>", "img": null, "categories_id": 1, "created_at": "2022-05-07T02:11:41.000000Z", "updated_at": "2022-05-07T02:11:41.000000Z" } }, { "id": 17, "ujians_id": 11, "questions_id": 1, "mulai": null, "berakhir": null, "durasi": 60, "isAnswer": 0, "created_at": "2022-05-07T02:53:56.000000Z", "updated_at": "2022-05-07T02:53:56.000000Z", "questions": { "id": 1, "title": "13", "question": "<p>Wahidin soedirohoesodo memilik peran penting dalam pergerakan kemerdekaan. Antara lain…22234232</p>", "img": null, "categories_id": 1, "created_at": "2022-05-02T10:39:13.000000Z", "updated_at": "2022-05-03T13:28:24.000000Z" } } ]
@php $no=1 @endphp @foreach($dataUjian as $row) @if($row->isAnswer == 0) <button class="btn btn-primary btn-sm" onclick="getUjian({{$row->questions_id}}, {{$row->id}},{{$row->ujians->users_id}})" >{{$no++}}</button> @else <button class="btn btn-danger btn-sm" disabled>{{$no++}}</button> @endif @endforeach
-
Unit testing with get request
I am trying to create a unit test for one of my api.
In the frontend, I send it this way...
params = { participants: JSON.stringify(participants), section: JSON.stringify(section), }; axios.get('/api/list', params)
while in the controller, it receives the params this way...
public function list(Request $request) { $participants = json_decode($request->participants); $section = json_decode($request->section); }
Now, I tried making a unit test out of this. by doing...
$params = [ 'participants' => ['id', 'name', 'rating'], 'section' => ['id', 'code'], ]; $this->get('/api/list'.http_build_query($params))->assertStatus(200) // $this->json('/api/list', $params)->assertStatus(200) // -> also tried this one // $this->getJson('/api/list', $params)->assertStatus(200) // -> also tried this one // $this->call('GET', '/api/list', $params)->assertStatus(200) // -> also tried this one
But none of them works, it always says
TypeError: json_decode(): Argument #1 ($json) must be of type string, array given
.So, the way I built the url and the params must be all wrong,
so my question here is that, what's the correct way of building the url so that it provides a correct url string format and the controller will json_decode the params?
-
Getting mongo authorization errors with userAdminAnyDatabase role
I am trying to get authorization working on a mongo database on a new Ubuntu machine. I have created an admin user with the role userAdminAnyDatabase:
admin> show users [ { _id: 'admin.mongoAdmin', userId: UUID("590a4465-625a-4fa0-af2e-0f2c75777ac5"), user: 'mongoAdmin', db: 'admin', roles: [ { role: 'userAdminAnyDatabase', db: 'admin' } ], mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ] } ]
but I get authorization errors when I try to do anything:
admin> use test switched to db test test> db.users.find({}) MongoServerError: not authorized on test to execute command { find: "users", filter: {}, lsid: { id: UUID("f3cf2fbc-bbea-4ceb-83a1-b842b5047e74") }, $db: "test" }
I know I am using the correct id/password, as when I try to run the mongo shell with a different password it fails to start with a password error.
Ubuntu version is 20.04.4 (Focal); Mongo version is 5.0.8:
% mongod --version db version v5.0.8 Build Info: { "version": "5.0.8", "gitVersion": "c87e1c23421bf79614baf500fda6622bd90f674e", "openSSLVersion": "OpenSSL 1.1.1f 31 Mar 2020", "modules": [], "allocator": "tcmalloc", "environment": { "distmod": "ubuntu2004", "distarch": "x86_64", "target_arch": "x86_64" } }
-
docker discord.py ffmpeg.exe was not found
My code works on windows fine I'm just stumped on how to migrate it to my docker server for stability reasons and my old vm shit the bed. bellow is my main playing loop
async def main_playing_loop(vc, ctx): global skip while len(queued[str(ctx.guild.id)]) > 0: try: print(vc.is_playing()) while vc.is_playing() or vc.is_paused(): await asyncio.sleep(2) skip_func(vc) pass except AttributeError: pass try: url = str(queued[str(ctx.guild.id)][0]) download_video(ctx, url) vc.play(discord.FFmpegPCMAudio(executable="ffmpeg.exe", source=str(ctx.guild.id) + ".mp3")) del queued[str(ctx.guild.id)][0] except: break
log of what its doing
discord_main_1 | [youtube] dQw4w9WgXcQ: Downloading android player API JSON discord_main_1 | [youtube] dQw4w9WgXcQ: Downloading webpage discord_main_1 | stoping discord_main_1 | [youtube] dQw4w9WgXcQ: Downloading android player API JSON discord_main_1 | [info] dQw4w9WgXcQ: Downloading 1 format(s): 251 discord_main_1 | [download] Destination: 866270239342460930.mp3 [download] 100% of 3.28MiB in 00:00 discord_main_1 | Ignoring exception in command play: discord_main_1 | Traceback (most recent call last): discord_main_1 | File "/usr/local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 85, in wrapped discord_main_1 | ret = await coro(*args, **kwargs) discord_main_1 | File "/usr/src/bot/main.py", line 125, in play discord_main_1 | vc.play(discord.FFmpegPCMAudio(executable="ffmpeg.exe", source=str(ctx.guild.id) + ".mp3")) discord_main_1 | File "/usr/local/lib/python3.10/site-packages/discord/player.py", line 225, in __init__ discord_main_1 | super().__init__(source, executable=executable, args=args, **subprocess_kwargs) discord_main_1 | File "/usr/local/lib/python3.10/site-packages/discord/player.py", line 138, in __init__ discord_main_1 | self._process = self._spawn_process(args, **kwargs) discord_main_1 | File "/usr/local/lib/python3.10/site-packages/discord/player.py", line 147, in _spawn_process discord_main_1 | raise ClientException(executable + ' was not found.') from None discord_main_1 | discord.errors.ClientException: ffmpeg.exe was not found. discord_main_1 | discord_main_1 | The above exception was the direct cause of the following exception: discord_main_1 | discord_main_1 | Traceback (most recent call last): discord_main_1 | File "/usr/local/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 939, in invoke discord_main_1 | await ctx.command.invoke(ctx) discord_main_1 | File "/usr/local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 863, in invoke discord_main_1 | await injected(*ctx.args, **ctx.kwargs) discord_main_1 | File "/usr/local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 94, in wrapped discord_main_1 | raise CommandInvokeError(exc) from exc discord_main_1 | discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: ffmpeg.exe was not found.
i have still got the old exe for ffmpeg i was using on win but that doesn't work on Ubuntu. any help is appreciated thanks.
-
Flask redirecting leads to time-out error
I have this simple redirect from '/' to '/home', handled by flask with
app.py
@app.route('/') #Redirects to home page def redirect_home(): return redirect("/home")
When I use it with my browser it always leads a connection timeout error, althoug when using cURL on my vps (with -L) it does lead to the webpage correctly
I believe it has to do with my nginx setup: sites-available
location / { proxy_pass http://127.0.0.1:5000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; }
I used to face this issue before on my old vps and I remember fixing it by adding something to the nginx configuration but I don't remember what it was
-
add nodes to dockers swarm from different servers
I am new to docker swarm, I read documentation and googled to the topic, but results was vague, Is it possible to add worker or manager node from distinct and separate Virtual private servers?
-
Configure Gmail API on Ubuntu VPS
How to configure Gmail API on a AWS Ubuntu VPS? I am able to make it work properly on my Linux Machine, but after I run the code on my VPS, it asks me to authenticate by visiting the URL. I copied the URL and tried authenticating myself. While authenticating myself in browser, I am redirected to
localhost:<random-port>?state=...
and cannot authenticate myself as it cannot connect to localhost. How can I configure this properly on my Ubuntu VPS?i have used the default code provided by google developers: https://developers.google.com/gmail/api/quickstart/python