Is there any way to write/append to a remote file via FTP? I need to append certain content in the file located in the server? Is there any way to do with shell script?
You can use cURL with the --append flag:
(FTP/SFTP) When used in an upload, this makes curl append to the target file instead of overwriting it. If the remote file doesn't exist, it will be created. Note that this flag is ignored by some SFTP servers (including OpenSSH).
See cURL man page.
Related
I have access to a remote server over ssh. I have only read (no write) access on the server. There is a zipped log file that I want to read.
But because I have only read access, I cannot first extract the file and then read it, because when I try to unzip, I get the message Read-only file system.
My idea was to redirect the output of the gunzip-command to some other command that can read from the standrat input and display the content in the console. So I do not write the unzipped file on the file system (that I do not have the right) but display it directly in the console. Until now I couldn't successfully do it.
How to achieve this goal? And is there any better way to do it?
Since you do not have permission to unzip the file, you will first need to view the list of contents and their path. Once you get that then you can view content using -p option of unzip command.
View contents
zipinfo your.zip
View file contents
unzip -p latest.zip wordpress/wp-config-sample.php
In case it is a .gz file then use: gunzip -c wordpress/wp-config-sample.php
Hope this helps!
I'm building an production site update script using expect and lftp.
I'm trying for sometime to do this simple thing: send a file overwriting if it exists. But I just can't find a command that allow me to overwrite destination on put. put -c just continues if it's the same file. But if it's different it does nothing.
Do I really have to check if the file exists and delete it in order to put the file in the server ? isn't there a direct command ?
If that's the only option, then there's another thing I couldn't find: a command to see if the file exists. My only option is to treat ls's output ?
I also accept recommendations if there's another ftp client that allows me to do these things in an easier manner.
LFTP offers a parameter for put which is a lowercase e.
This allows you to remove the file before uploading it, as opposed to an overwrite option (which LFTP doesn't appear to inherently support). Things like prompt could be available, but if we're strictly discussing LFTP, I would recommend using that option, ala:
put -e file.txt
From the LFTP man pages.
Im trying to copy a zip file located on a server by a ssh2 library.
the way i'm about to do is using less command and write it down on client side.
Less -r -L -f zipfile
but the output file is bigger than the original.
i know this not a good practice but i have to.
so how can i handle this to have my zip file on the client machine?
Is Less an mandatory command to do that ?
You can simply use scp to achieve that by providing user and host and then typing the directory, where to copy the file from the server to local host, like on the example below:
scp your_username#remotehost.edu:foobar.txt /some/local/directory
Im trying to do a bash script and i need to download certain files with wget
like libfat-nds-1.0.11.tar.bz2 but after some times the version of this file may change so i would like to download a file that start with libfatnds and ends in .tar.bz2 .Is this possible with wget?
Using only wget, it can be achieved by specifying filename with wildcards in the list of accepted extensions.
wget -r -np -nd --accept='libfat-nds-*.tar.bz2'
The problem is that HTTP doesn't support wildcard downloads
. But if there is content listing enabled on the server or you have a index.html containing the available file names you could download that, extract the file name you need and then download the file with wget.
Something in this order
Download the index with curl
Use grep and/or sed to extract the exact file name
Download the file with wget (or curl)
If you pipe the commands you can do it on one line.
I tried something like:
wget ftp://username:password#ftp.somedomain.com/bla/blabla.txt -x /home/weptile/public_html/bla/blabla.txt
Appereantly -x writes the output :) I thought it was overwriting the file I need.
So what I'm trying to do is do daily updates on blabla.txt in this specific subdirectory from an external ftp file. I want to get the file from ftp and overwrite the old file on my server.
Use wget -N to overwrite existing files.
If you get stuck on stuff like this, try man wget or heck, even Google.