Lftp sftp get - script renames the local file with suffix tilde


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Lftp sftp get - script renames the local file with suffix tilde
# 1  
Old 12-22-2014
Lftp sftp get - script renames the local file with suffix tilde

Hi,
Below script used for sftp get,
Code:
#/bin/bash
USER=xxx
PASS=xxx
HOST=xxx
REMOTE_FILE=$1
LOCAL_FILE_LOC=$2
cd $LOCAL_FILE_LOC
lftp sftp://$USER:$PASS@$HOST:10022 -e "get $REMOTE_FILE; bye"

If file does not exist in sftp server, and file (same as remote file name) exists in local dir, above script throws error and renames local file with suffix ~.
For example: If file name is xyz_file after script execution it throws error:
Code:
get: Access failed: /xyz_file: Specified file path is invalid. and renames the local file to 'xyz_file~'

Any idea why its happening.

Last edited by Don Cragun; 12-22-2014 at 03:46 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 12-22-2014
It looks like you're calling your script with /xyz_file as the 1st operand and /xyz_file either does not exist on the host or, if it does exist, you don't have permission to read it.
# 3  
Old 12-22-2014
Yes. file does not exit in server. But why command renames the local file with suffix tilde? 'xyz_file~'
# 4  
Old 12-22-2014
It does that because the software you're running assumes that it will be replacing an existing file and makes a backup copy before checking whether or not there is a file to copy.

I would consider that assumption a bug; it seems to me that it should at least move the file back to its original name if it couldn't transfer any data. But, I'm not familiar with lftp. What does its man page say it will do in this case?
# 5  
Old 12-22-2014
Thanks.
As per Man page, xfer:make-backup (boolean) : when true, lftp renames pre-existing file adding ‘~’ suffix instead of overwriting it.
Default value for above variable is ‘yes’. So before executing the get command disable the backup option for the current session.

Code:
lftp sftp://$USER:$PASS@$HOST:10022 -e "set xfer:make-backup no; get $REMOTE_FILE; bye"

It worked.

Last edited by rbatte1; 06-15-2017 at 07:00 AM.. Reason: Added CODE tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

lftp is not working.how to replace lftp with expect utility using same .cfg file.

We have lftp command inside shell file. which is intern calling .cfg file for transferring the file from one server to other. Below command to not working. lftp -e "set net:max-retries 1; set net:reconnect-interval-base 1; put -E -O /destinationdir/inbox/ /sourcedir/test.txt; bye" -u... (4 Replies)
Discussion started by: johnsnow
4 Replies

2. UNIX for Dummies Questions & Answers

Transfer image file from local to remote with sftp

Hi. I have managed to transfer a file from remote to my raspberry pi, but I have the camera mounted on the Raspbien so I would like to transfer the image the other way. I use this line: sshpass -p 'PASSWORD' scp -- USER@ssh.servername.com:/www/cam/image.jpg /home/pi/shared/web/image.jpg (4 Replies)
Discussion started by: brickglow
4 Replies

3. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

4. Shell Programming and Scripting

lftp script to connect to external sftp site and download to internal ftp and then send email

Hi there, I'm new to shell scripting and need some help if possible? I need to create a shell script (.sh) to run as a cron job on an ubuntu linux server to connect to an external sftp sites directory using credentials (which I have) and then download to our internal ftp server and then copy... (3 Replies)
Discussion started by: ghath
3 Replies

5. Shell Programming and Scripting

I need a korn shell script that renames and copies

I have 68 servers whose /etc/ntp.conf file have the wrong NTP server name and they need to be updated with a different or correct NTP server name. I am doing this on AIX Here is what I would like. and I would need a script that would rename the old /etc/ntp.conf and add a date stamp to it ... (1 Reply)
Discussion started by: jesifra
1 Replies

6. UNIX for Advanced & Expert Users

lftp: Option to lftp a file, wait and download a file as soon as its created

Please let me know what is lftp options combination to wait and download a file from target as soon as its gets created. I tried with different options but not able to get it working as I need any help would be appreciated (4 Replies)
Discussion started by: bmkux
4 Replies

7. UNIX for Dummies Questions & Answers

File renames with timestamp urgent

Hi Gurus, I am novice in unix. I had a requirement where i should get the file when it is loaded in a folder & append time stamp to it & relace that file with timestamp. i.e., Suppose i have a file in home/input folder as abc.xml I want to get that file & rename it as... (4 Replies)
Discussion started by: pssandeep
4 Replies

8. Shell Programming and Scripting

Delete Duplicate records from a tilde delimited file

Hi All, I want to delete duplicate records from a tilde delimited file. Criteria is considering the first 2 fields, the combination of which has to be unique, below is a sample of records in the input file 1620000010338~2446694087~0~20061130220000~A00BCC1CT... (5 Replies)
Discussion started by: irshadm
5 Replies

9. Shell Programming and Scripting

how to extract a tilde delimited file in unix

i have a file in unix in which datas are like this 07 01 abc data entry Z3 data entry ASSISTANT Z3 39 08 01 POD peadiatrist Z4 POD PeDIATRY Z4 67 01 operator specialist 00 operator UNSPECIFIED A0 00 ... (12 Replies)
Discussion started by: trichyselva
12 Replies

10. Shell Programming and Scripting

replacing commas with tilde in csv file.

hello all, i have a comma delimited file. i want to replace the commas in the file with the tilde symbol using sed. how can i do this? thanks. (4 Replies)
Discussion started by: femig
4 Replies
Login or Register to Ask a Question