FTP Script to move files from Suse server to ftp - linux

We need to move all the files from particular folder to ftp server. We wrote a script but getting directory not found exception. Below is the script.
#!/bin/sh
HOST='192.168.1.100'
USER='ramesh'
PASSWD='rameshftp'
ftp -inv $HOST << EOF
user $USER $PASSWD
cd /home/Ramesh
put *.zip
bye
EOF
Our requirement is to copy all the files which resides in some directory in Suse Linux Server and copy to FTP server. for eg: Copy all the contents from "/home/Ramesh" directory and put into ftp server.

You can do this in one line with ncftp:
ncftpput -u username -p password ftp-host-name /path/to/remote/dir /path/to/local/dir/*
See http://linux.die.net/man/1/ncftp for more info

Related

How to save FTP session logs in file in Linux

I am using a bash script in Linux to transfer files to a server. My script is running from cron and I have directed output to a file but I cannot know from logs if the file has been transferred to B server or not.
This is the cron:
1>>/home/owais/script_test/logs/res_sim_script.logs 2>>/home/owais/script_test/logs/res_sim.logs
And the FTP is as below:
cd ${dir}
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
lcd $dir
cd $destDir
bin
prompt
put FILENAME
bye
The only thing that I get in the logs is:
Local directory now Directory_Name
Interactive mode off.
Instead of using FTP, there is rsync. Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to or from another host over any remote shell, or to, or from a remote rsync daemon.
More information at the following webpage, https://linux.die.net/man/1/rsync
I have used ftp -inv Host << EOF >> LogFilePath and it worked. Thank you all for the support

shell script: ftp to check existing file

I've a simple shell script to transfer daily log file to another Windows FTP.
The problem is if the file is already there, it will still uploading a new one even though the file name is exactly the same.
How to perform a quick check on this script? If the file is there, then it won't proceed with FTP transfer
ftp -n -v $HOST << EOT
user $USER $PASSWD
prompt
bin
mput $FILE
bye
EOT
It is easy in Unix with ftp. First login to the system through ftp and run a ls -ltr command through ftp and list the files in a history.txt file(see below my example) and while transferring the file first check whether that file is already available in history file or not. And if available do not transfer that file. I do it like below:-
HISTORY_FILE="history.txt"
ftp -n -v $HOST << EOT
user $USER $PASSWD
prompt
bin
ls -rtE $HISTORY_FILE
bye
EOT
Now you can use below command to check:-
ISFILENAMEEXIST=$(cat $HISTORY_FILE | grep $FILE)
Now if the file exist in history.txt, do not send that file and if not available send it through ftp.

Create directory in local machine(Linux) by using sftp

I have tried the command below to create a directory after I downloaded a file from sftp. But unfortunately the command couldn't run. What's the error between this command?
sftp username#servername:/server/path/xxx.txt lmkdir /my/home/directory/new_path
to create a directory just use
lmkdir dirName
http://www.bic.mni.mcgill.ca/users/kate/Howto/sftp_notes.html
jimmy#moody:~$ sftp localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is 97:52:17:f7:e7:c4:5b:68:00:62:6d:42:2c:ee:5a:60.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
jimmy#localhost's password:
Connected to localhost.
sftp> lmkdir dirName
sftp> exit
jimmy#moody:~$ ls dirName/
lmkdir path
Create local directory specified by path.
Also you might want to use
lcd path
Change local directory to path.
lls [ls-options [path]]
Display local directory listing of either path or current directory if path is not specified. ls-options
may contain any flags supported by the local system's ls(1) command. path may contain glob(3) characters
and may match multiple files.
The command you are invoking is invalid. As others here have mentioned the command to create a local directory while in the sftp shell is lmkdir, however you are not invoking the shell, you are trying to copy the file into a directory while creating the directory.
The way your current command is being interpreted is as a request to download "servername:/server/path/xxx.txt" into a file called "lmkdir" followed by an invalid option of "/my/home/directory/new_path" which sftp doesn't understand.
What you want to do instead is
mkdir /my/home/directory/new_pathsftp
sftp username#servername:/server/path/xxx.txt /my/home/directory/new_pathsftp
or from the sftp shell:
$ sftp username#servername
Connected to username#servername
sftp> lmkdir /my/home/directory/new_pathsftp
sftp> lcd /my/home/directory/new_pathsftp
sftp> get /server/path/xxx.txt
sftp> quit
You can include the three lines executed in the sftp shell as a batch file to be executed when connected, eg
sftp username#servername -b batchfile
where batchfile contains the following
lmkdir /my/home/directory/new_pathsftp
lcd /my/home/directory/new_pathsftp
get /server/path/xxx.txt
quit

How can I copy file from local server to remote with creating directories which absent via SSH?

I can copy file via SSH by using SCP like this:
cd /root/dir1/dir2/
scp filename root#192.168.0.19:$PWD/
But if on remote server some directories are absent, in example remote server has only /root/ and havn't dir1 and dir2, then I can't do it and I get an error.
How can I do this - to copy file with creating directories which absent via SSH, and how to make it the easiest way?
The easiest way mean that I can get current path only by $PWD, i.e. script must be light moveable without any changes.
This command will do it:
rsync -ahHv --rsync-path="mkdir -p $PWD && rsync" filename -e "ssh -v" root#192.168.0.19:"$PWD/"
I can make the same directories on the remote servers and copy file to it via SSH by using SCP like this:
cd /root/dir1/dir2/
ssh -n root#192.168.0.19 "mkdir -p '$PWD'"
scp -p filename root#192.168.0.19:$PWD/

mput Not Transferring All Files During FTP Transfer

I'm having issues with my Unix FTP script...
It's only transferring the first three files in the directory that I'm local cd'ing into during the FTP session.
Here's the bash script that I'm using:
#!/bin/sh
YMD=$(date +%Y%m%d)
HOST='***'
USER='***'
PASSWD=***
FILE=*.png
RUNHR=19
ftp -inv ${HOST} <<EOF
quote USER ${USER}
quote PASS ${PASSWD}
cd /models/rtma/t2m/${YMD}/${RUNHR}/
mkdir /models/rtma/t2m/${YMD}/
mkdir /models/rtma/t2m/${YMD}/${RUNHR}/
lcd /home/aaron/grads/syndicated/rtma/t2m/${YMD}/${RUNHR}Z/
binary
prompt
mput ${FILE}
quit
EOF
exit 0
Any ideas?
I had encountered same issue, I have to transfer 400K files but mput * or mput *.pdf was not moving all files in one go
tried timeout :fails
tried -r recursive :fails
tried increasing Data/control timeout in IIS :fails
tried -i
Prompt
scripting fails
Finally went to use portable filezilla connect to from source and transferred the all files

Resources