mget No Such file or directory - linux

I'm connected to one of our file servers and am trying to pull down (via ftp and mget) a folder to a local directory. 50% of the mget command works successfully until it gets to a JAR file that is absolutely there on the server. It gives me the following error:
local: dist/MyProgram.jar remote: dist/MyProgram.jar
local: dist/MyProgram.jar: No such file or directory
The command I am using is a simpl mget
ftp> prompt
ftp> mget *
I am absolutely in the right directory and absolutely have a solid connection. Setting the prompt flag to prevent me from being prompted on each get. Any ideas?

wget -r ftp://name:passwd#ftp.com/somedir/

That's because mget doesn't behave recursively. I thought it would recurse down my directory tree and copy everything over as-is. You need to run it at every level of your project. It was treating dist/MyProgram.jar as a filename.

Related

shell scripts runs manually but not in crontab

i have shell script to FTP a file from one server to another server called abc.sh below is the code inside it
#!/bin/bash
HOST='10.18.11.168'
USER='india'
PASS='India#2017'
FILE='inload.dat'
DIRECTORY='/inloading'
ftp -n $HOST <<END_SCRIPT
user $USER $PASS
cd $DIRECTORY
put $FILE
quit
END_SCRIPT
exit 0
i am able to run it using ./abc.sh and file also gets copied to remote server.
But when i use in crontab it is not ftp the file
below is the crontab entry
15 01 * * * /user/loader/abc.sh > /user/loader/error.log 2>&1
in the error.log it shows as local: inload.dat: No such file or directory
You're referencing the file inload.dat, which is relative to the directory the script is run from. When you run the script as ./abc.sh it looks for an inload.dat in the same directory.
Cron chooses which directory to run your script from when it executes (IIRC it generally defaults to /root or your HOME directory, but the specific location doesn't matter), and it's not necesarily the same directory that you're in when you run ./abc.sh.
The right solution is to make FILE and absolute path to the full location of inload.dat, so that your script no longer depends on being run from a certain directory in order to succeed.
There are other options, such as dynamically determining the directory the script lives in, but simply using absolute paths is generally the better choice.
Your local path is probably not what you want it to be. Before executing the ftp command, add a cd to the directory of where the file is located. Or have the full path name to the file $FILE.

copy/move files on remote server linux

I log into server_a and run .sh file, which has the following script:
scp user#server_b:/my_folder/my_file.xml user#server_b:/my_new_folder/
to copy files from my_folder to my_new_folder at server_b. It doesn't throw an error, but no files are copied.
Notes:
server_b is accessed by the pre-set rsa_keys.
server_a: unix
server_b: ubuntu
can SCP files from/to these servers without any issues
The end goal is to move or copy/remove files.
There are two possibilities:
Connect from server_a to server_b and do local copy:
ssh user#server_b "cp /my_folder/my_file.xml /my_new_folder/"
Do copy over the server_a. Your method would require the server_b to be able to authenticate to itself, which is probably not the case:
scp -3 user#server_b:/my_folder/my_file.xml user#server_b:/my_new_folder/
Also note that your code copies only one file and not files as you write in the title.
If you are logged on to the server, why are you authenticating again:
scp user#server_b:/my_folder/my_file.xml user#server_b:/my_new_folder/
You should be in the directory of file or simply use scp and use -v parameter to see the debug information.
Run as follows:
scp -v /my_folder/my_file.xml user#server_b:/my_new_folder/
It is not a directory nor it is recursive, so you do not need to -r parameter.

sftp script failing when one of the sftp statement fails in Linux

I am having an OpenSSH sftp script which transfer the files from a SFTP server (Solaris) to application server (Linux). Here the scenario is the transfer happens from different location and same files are transferred backup to SFTP server different location. But if any of the transfers fail due to file is not available, it is not continuing the remaining sftp commands. Instead it just comes out of the code. Below is the script.
export SSHPASS=*******
/usr/local/bin/sshpass -e sftp -oPort=22 -oBatchMode=no -b - rkwlahtt#10.204.140.14 << !
cd /home/rkwlahtt/Inbound
mget *.*
rm *.*
cd /home/rkwlahtt/Inbound/Adhoc
mget *.*
rm *.*
cd /home/rkwlahtt/Archive/Inbound
mput *.TXT
mput *.txt
cd /home/rkwlahtt/Archive/Adhoc
mput *.xlsx
bye
!
Here in the above script when I am trying to mget from /home/rkwlahtt/Inbound folder and if file doesn't exist, it just comes out of the sftp code instead of going to next command that is cd /home/rkwlahtt/Inbound/Adhoc and mget. This is the same situation while mput too.
This is the first time we are transferring from different location in the same code. And this is creating issue in our transferring.
Please let me know what can be done to resolve this issue.
You can suppress an abort on error on a per-command basis using a - prefix:
-mget *.*
Another options is to remove the -b - switch.
The -b does two things. First it enables a batch mode (= abort of any error), second it sets a script file. Except when you use - instead of a script file name, in which case the commands are read from the standard input, what is the default. You do not need the second effect (as you use - anyway) and you do not want the first.
Even without the switch, you can still feed the commands using input redirection, as you are doing.
Though you need to make sure no command will ask for any input. As then some of your command will be used as the input instead of being executed.
See https://man.openbsd.org/sftp#b

SFTP - WinSCP: Zip a file/folder

I'm transferring a file to SFTP and then trying to zip it with WinSCP. It's not working.
After my put command, I'm using the following command.
zip -r "!?&SFTP Folder Path\MyFile.txt:?SFTP Folder Path\MyFile.zip!" !&
What am I doing wrong? What should I be doing? If I only want to zip a/any file with specific extension or folder, what changes do I make?
Update:
I'm getting the following log output after a file has been copied over to the sftp
...
batch continue Searching for host...
Connecting to host...
Authenticating...
Using username "admin". Authenticating with pre-entered password. Authenticated. Starting the session...
I'm using the following code after put cmd line.
option batch continue
call zip -r "/sftp folder/Myfile.zip" Myfile.csv
close
exit
Your syntax is a custom command. The custom commands is a GUI feature of WinSCP, it has nothing to do with the scripting.
In WinSCP scripting use the call command.
call zip -r /path/MyFile.zip file1.dat file2.dat ...
Though make sure you are allowed to execute shell commands on the server.

`cp -pr` behaving differently on two different RHEL servers

I am using a script on RHEL server where I'm copying a backup of the /etc/syslog.conf file before making configurable changes in it. I used the below command in the script:
cp -pr /etc/syslog.conf /etc/syslog.conf.bkp.`date +"%d%m%Y"`
The script ran absolutely fine on one RHEL server, but on the other it shows the below error:
cp: cannot stat `/etc/syslog.conf': No such file or directory
I also checked the /etc/syslog/conf file exists in the server just fine.
Why is the difference of behaviour. How to resolve it ?
cp: cannot stat is mainly because cp command can't see the file. It can be for two reasons.
File is not present
You don't have permission to view the file.
If you check these two things you should be able to find the answer

Resources